[Gvsig_english] Retrieve FPoint2D Coordinate From FPolyline2D

Francisco José Peñarrubia fjp at scolab.es
Thu Aug 27 11:36:06 CEST 2009


Hello Bong.

Some tips:

Easy (but slow):

                IGeometry geom = adapter.getShape(i);
                if (ct != null) {
                    if (bMustClone)
                        geom = geom.cloneGeometry();
                    geom.reProject(ct);

                }
                Geometry jtsGeom = geom.toJTSGeometry();
                Coordinate[] coords = jtsGeom.getCoordinates();

Quick:

        int theType;
        // Use this array to store segment coordinate data
        double[] theData = new double[6];
        PathIterator theIterator;

        theIterator = g.getPathIterator(null, FConverter.FLATNESS);
        ArrayList arrayCoords = new ArrayList();
        while (!theIterator.isDone()) {
            theType = theIterator.currentSegment(theData);
            if (theType == PathIterator.SEG_MOVETO) {
                arrayCoords.add(new Point2D.Double(theData[0], theData[1]));
            } else if (theType == PathIterator.SEG_LINETO) {
                arrayCoords.add(new Point2D.Double(theData[0], theData[1]));
            } else if (theType == PathIterator.SEG_CLOSE) {
                Point2D firstPoint = (Point2D) arrayCoords.get(0);
            }
            theIterator.next();
        }


ArrayCoords will be an array of Point2D. You can create an array o 
FPooint2D if you prefer it.

Hope this helps, but take care. In gvSIG 2.0 this will change and will 
be different.

Fran Peñarrubia
gvSIG team
www.scolab.es

Note: FConverter.FLATNESS is useful if you deal with curves. They will 
be converted to line segments.


Bong Thai Kwong escribió:
> dear all,
>
> goodday!
>
> i need assistance on how to use java code to retrieve coordinates for 
> all the vertices in a FPolyline2D. i tried to use the path iterator.
>
> thepolyline2d.getPathIterator(null);
>
> however, i'm not able to retrieve the coordinate from each iterator. 
> plis throw some light as to how to retrieve it.
>
> appreciate, 10s.
>
> regards, bongtk
>
> _______________________________________________
> Gvsig_internacional mailing list
> Gvsig_internacional at listserv.gva.es
> http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional
>   



More information about the Gvsig_internacional mailing list