Re: [OpenMap Users] shapefiles - getting the outerRing

From: C S <usmsci_at_yahoo.com>
Date: Mon, 29 Nov 2010 11:20:55 -0800 (PST)

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 shouldn't 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 co
e 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 double[6];
                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 an indicator
> of which was would be the outer ring.
> >
> >  shapeFile = ne
 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"]
Received on Mon Nov 29 2010 - 14:21:41 EST

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