Thanks everyone.  I added the CGAlgorithms.isCCW(Coordinate[]) call in
my logic, but apparently, my problem is that for some of the polygons
I'm trying to render (in google maps, not using geotools renderer) have
holes.  When I get the points for a polygon, I'm getting back points
from all rings, inside and outside.  My problem may be that I'm not
extracting the polygons correctly.  Here's my code:


FeatureSource featureSource = ds.getFeatureSource(typeName);
FeatureCollection featureCollection = featureSource.getFeatures();
FeatureIterator iterator = featureCollection.features();
try {
  while (iterator.hasNext()) {
    Feature feature = iterator.next();
    FeatureType featureType =  feature.getFeatureType();
    for (int i = 0; i < feature.getNumberOfAttributes(); i++) {
      String aName = featureType.getAttributeType(i).getLocalName();
      String aValue = feature.getAttribute(i).toString();
      if (!aName.equals("the_geom")) log.debug(aName + " = " + aValue);
    }
    Geometry geometry = feature.getDefaultGeometry();
    Coordinate centroid = geometry.getCentroid().getCoordinate();
    String strCentroid = centroid.y + "," + centroid.x;
    log.debug("centroid: " + strCentroid);
    
    double distanceTolerance = 0.001;
    log.debug("# of polygons: " + geometry.getNumGeometries());
    for (int i = 0; i < geometry.getNumGeometries(); i++) {
      log.debug("polygon [" + i + "]");
      Geometry g =
TopologyPreservingSimplifier.simplify(geometry.getGeometryN(i),
distanceTolerance);
      log.info("GeoType: " + g.getGeometryType());
      Coordinate[] coords = g.getCoordinates();
      log.debug("Num Geometries: " + g.getNumGeometries());
      log.debug("#coords: " + coords.length);
      
      String strPolygon = "";
      if (CGAlgorithms.isCCW(coords) {
        for (int j = coords.length -1; j >=0; j--) {
          strPolygon += coords[j].y + "," + coords[j].x;
          if (j > 0) strPolygon += " ";
        }
      } else {
        for (int j = 0; j < coords.length; j++) {
          strPolygon += coords[j].y + "," + coords[j].x;
          if (j < coords.length - 1) strPolygon += " ";
        }
      }
      log.debug("polygon: " + strPolygon);
    }
  }
} finally {
  iterator.close();
}


-----Original Message-----
From: Michael Bedward [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 05, 2008 7:15 PM
To: Jody Garnett; Angel, Eric; [email protected]
Subject: Re: [Geotools-gt2-users] Clockwise/Counter Clockwise

Ah !  So for Eric's Coordinate array he can use the static
CGAlgorithms.isCCW(Coordinate[]) function.

These queries are great for exploring the back passages of geotools :)

Just had a look at the code for that function - those jts folk are so
clever !

Michael

On Fri, Jun 6, 2008 at 7:10 AM, Jody Garnett <[EMAIL PROTECTED]>
wrote:
> I found the following code in the SDO utility class; it is not really
the
> best location for this sort of thing...
>
>   /** Used to test for Counter Clockwise or Clockwise Linear Rings */
>   private static RobustCGAlgorithms clock = new RobustCGAlgorithms();
>
>   public static CoordinateSequence counterClockWise(
>       CoordinateSequenceFactory factory, CoordinateSequence ring) {
>       if (clock.isCCW(ring.toCoordinateArray())) {
>           return ring;
>       }
>       return Coordinates.reverse(factory, ring);
>   }
>
> Michael Bedward wrote:
>>
>> Hi Eric
>>
>> There may be an easier way, but the JTS class CoordinateArrays has a
>> method ensureOrientation which might help you.
>>
>> Michael
>>
>> On Thu, Jun 5, 2008 at 1:43 PM, Angel, Eric <[EMAIL PROTECTED]>
wrote:
>>
>>>
>>> Does anyone know of a way to determine if a Coordinate[] is CW or
CCW?
>>>  My assumption of CW ordering creates really bad polygons from the
US Census
>>> shapefiles (Current Place).
>>>
>>>
>>> Thanks,
>>>
>>> Eric
>>>
>
>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to