Hi,

                 As to get the CRS of a Polygon.


    public static void main(String[] args) {
        try {
            GeometryFactory geometryFactory =
JTSFactoryFinder.getGeometryFactory( null );
            WKTReader reader = new WKTReader( geometryFactory );
            Polygon polygon = (Polygon) reader.read("POLYGON((-72.0 -8.0, "
+
                                                              "-71.0 -8.0, "
+
                                                              "-71.0 -9.0, "
+
                                                              "-72.0 -9.0, "
+
                                                              "-72.0
-8.0))");

            System.out.println("PolĂ­gono = " + polygon.getArea() + " / " +
polygon.getLength() + " / " + polygon.getNumPoints() + " / " +
polygon.getNumGeometries() + " / " + polygon.getDimension());

            System.out.println(polygon.getBoundary().within(polygon));

            System.out.println(polygon.getBoundary().intersects(polygon));

            System.out.println(polygon.getGeometryType() +
"---------------------------");

            CoordinateReferenceSystem sourceCRS = CRS.decode(here CRS of
polygon);
            CoordinateReferenceSystem targetCRS = CRS.decode(here SAD69
Coordinate Reference System "GCS_South_American_1969");

            MathTransform transform = CRS.findMathTransform(sourceCRS,
targetCRS);

            Geometry targetGeometry = JTS.transform(polygon.getBoundary(),
transform);

            System.out.println(targetGeometry.getCoordinates());
//            ReprojectPolygonDemo rpd = new ReprojectPolygonDemo();
//            rpd.demo(9);
            System.out.println("");

        } catch (TransformException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null,
ex);
        } catch (NoSuchAuthorityCodeException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null,
ex);
        } catch (FactoryException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null,
ex);
        } catch (MismatchedDimensionException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null,
ex);
        } catch (ParseException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null,
ex);
        }
    }
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to