Re: [OpenMap Users] shapefiles - getting the outerRing

From: C S <usmsci_at_yahoo.com>
Date: Thu, 9 Dec 2010 11:09:58 -0800 (PST)

Don,

  Sorry to e-mail you again since my last e-mail but I went ahead and checked the trunk in the openmap repository and the code in question in the Geo class to calculate an area doesnt seem to handle rings(defined as a cutout) in the list of points..unless i am missing something. It just seems to go down the elements in the enumeration and calculates the angles. Sorry again for another response.

Chad

--- On Tue, 11/30/10, Don Dietrick <dfdietrick_at_gmail.com> wrote:

> From: Don Dietrick <dfdietrick_at_gmail.com>
> Subject: Re: [OpenMap Users] shapefiles - getting the outerRing
> To: "C S" <usmsci_at_yahoo.com>
> Cc: openmap-users_at_bbn.com
> Date: Tuesday, November 30, 2010, 7:09 PM
> Hi CS,
>
> Have you tried rendering these shape files with all these
> holes?  Do
> they render properly? Seems like that would be the easiest
> way to tell
> if the code was working like you hope it is.
>
> I think your area calculation is OK for estimations, and
> should be OK
> for relative comparisons between parts, but it's not an
> accurate
> answer - I'd check out the
> com.bbn.openmap.geo.GeoArray.area() method
> if precision really matters.
>
> As long as each part starts and ends on the same
> coordinate, and the
> coordinates are in the right order, it should render
> properly.  If you
> need analysis done at a mathematical level, I think you
> need to do
> what you are doing.
>
> Hope this helps,
>
> Don
>
> On Mon, Nov 29, 2010 at 2:20 PM, C S <usmsci_at_yahoo.com>
> wrote:
> > Don,
> >
> >  thanks for the response. My shapefile that i have
> been dealing with had a large number of shapes and for each
> shape many of them are made up of more than 1 ring. I wrote
> a little function to tell me which ring had the biggest area
> by calculating the area of an irregular polygon and
> sometimes the first ring is not bigger than some of the
> other rings.
> >
> > The idea was that, assuming that all inner rings
> should have a smaller area than the outer ring and none of
> the other rings touch one another. Also rings should
> cross one another -- all this according to the definition of
> a valid shapefile on ESRI's website. I also believe that
> according to ESRI the order of the rings for each shape
> doesn't have any special meaning, leading me to believe that
> the outer ring did not have to be the first one.
> >
> > The area of an irregular polygon is defined on wiki
> here: http://en.wikipedia.org/wiki/Polygon
>  under the Area and Centroid section, the 3rd algorithm. As
> stated before there are various times where the first ring
> for each shape is not the largest according to this
> calculation.
> >
> >
> > So gathering from your response i need to verify that
> the first ring should be the biggest and if it isn't then
> either that area calculation somehow is wrong or the
> shapefile wasnt created correctly.
> >
> > If there is no particular sequence to the rings then
> you have an optimization problem when calculating the area
> of a polygon with internal rings which can only be correctly
> done once you subtract out all the areas of the inner rings.
> You first have to get the outer ring which potentially could
> be time consuming if you have a polygon, in my case, that
> has 2000 rings total. calculating the area of each one to
> find out the biggest one could be very costly. Also finding
> the ring that is clockwise cannot be determined if the rings
> are irregular until you have read most, if not all, the
> points which is also time consuming and costly. Perhaps
> there is a function to check for only clockwise rings?
> >
> > I am fairly confident that my area function works
> correctly. Below i will leave you with the code. Perhaps you
> could verify or someone could that has a shapefile handy.
> The only argument is a openmap Shape, code in java.
> >
> > protected double getArea(Shape shape) {
> >        double area = 0.0;
> >        double prev_x = 0;
> >        double prev_y = 0;
> >        PathIterator i =
> shape.getPathIterator(null);
> >
> >        while (!i.isDone()) {
> >                double[] points = new
       int shapeType =
> i.currentSegment(points);
> >
> >                if(shapeType ==
> PathIterator.SEG_MOVETO)
> >                {
> >                        prev_x =
> points[0];
> >                        prev_y =
> points[1];
> >                }
> >                else if(shapeType ==
> PathIterator.SEG_LINETO)
> >                {
> >                area += ( prev_x * points[1] )
> - ( prev_y * points[0]);
> >                        prev_x =
> points[0];
> >                        prev_y =
> points[1];
> >
> >                }
> >
> >                i.next();
> >
> >
> >          }
> >                area =
> java.lang.Math.abs(area);
> >                return area * 0.5f;
> > }
> >
> >
> > Would love to hear your feedback to anyone interested
> - thanks a lot in advance!
> >
> >
> >
> > --- On Tue, 11/23/10, Don Dietrick <dfdietrick_at_gmail.com>
> wrote:
> >
> >> From: Don Dietrick <dfdietrick_at_gmail.com>
> >> Subject: Re: [OpenMap Users] shapefiles - getting
> the outerRing
> >> To: "C S" <usmsci_at_yahoo.com>
> >> Cc: openmap-users_at_bbn.com
> >> Date: Tuesday, November 23, 2010, 9:22 AM
> >> Hi,
> >>
> >> I believe the outer ring is the first one in the
> array, and
> >> that
> >> coordinates are always clockwise with that outer
> ring (its
> >> in the
> >> shapefile specification), and change direction for
> the next
> >> ring, and
> >> then back and forth for subsequent rings.
> >>
> >> Hope this helps,
> >>
> >> - Don
> >>
> >>
> >> On Thu, Nov 18, 2010 at 10:26 AM, C S <usmsci_at_yahoo.com>
> >> wrote:
> >> > Hi again all,
> >> >
> >> >  I was wondering if there was a way to
> retrieve
> >> information about the outer ring of each
> shapeRecord of a
> >> shapefile. It doesnt look like ESRIRecord or any
> of its
> >> subclasses offer any way to look into each record
> of a
> >> shapefile and give you info about clockwise or
> >> counter-clockwise orientation of rings. below is a
> small
> >> snippet of code for reference. I have done a
> shpdump on the
> >> shapefiles as well and there doesnt seem to be a
ould be the outer ring.
> >> >
> >> >  shapeFile = new ShapeFile(shpInputfile);
> >> >  shapeCount = dbf.getRowCount();
> >> >
> >> > for (int i = 1; i <= shapeCount; i++) {
> >> > ESRIPolygonRecord shapeRecord = null;
> >> >
> >> > shapeRecord = (ESRIPolygonRecord)
> >> shapeFile.getNextRecord();
> >> >
> >> > for (int polyIndex = 0; polyIndex <
> >> shapeRecord.polygons.length; polyIndex++) {
> >> >    ESRIPoly.ESRIFloatPoly poly =
> >> (ESRIPoly.ESRIFloatPoly)
> shapeRecord.polygons[polyIndex];
> >> >
> >> > .......
> >> >
> >> > }
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > [To unsubscribe to this list send an email to
> "majdart_at_bbn.com"
> >> > with the following text in the BODY of the
> message
> >> "unsubscribe openmap-users"]
> >> >
> >>
> >
> >
> >
> >
>
> --
> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
> with the following text in the BODY of the message
> "unsubscribe openmap-users"]
>


      

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Dec 09 2010 - 14:10:42 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:10 EDT