Instead of

DefaultGeocentricCRS.CARTESIAN

try this

CRS.decode("EPSG:3576"); //http://spatialreference.org/ref/epsg/3576/



2013/2/14 serega_sh <[email protected]>

> Hi guziy, unfortunately I'm new to geotools and I'm really weak in all that
> stuff about projection.
>
> Here is my code:
> *//I do try to transform my lat,lon to planar x,y*
>     private static Coordinate transformToPlanar(Coordinate source) throws
> FactoryException, TransformException{
>         CoordinateReferenceSystem srcCRS = DefaultGeographicCRS.WGS84;
>         CoordinateReferenceSystem destSRC = DefaultGeocentricCRS.CARTESIAN;
>         boolean lenient = true; // allow for some error due to different
> datums
>         MathTransform transform = CRS.findMathTransform(srcCRS, destSRC,
> lenient);
>         return JTS.transform(source, null ,transform);
>     }
> *//from x,y to lat,lon to output to KML*
>     private static Geometry transformToGeo(Geometry source) throws
> FactoryException, TransformException{
>         LOG.info("transformToGeo: {}",source);
>         CoordinateReferenceSystem srcCRS = DefaultGeocentricCRS.CARTESIAN;
>         CoordinateReferenceSystem destCRS = DefaultGeographicCRS.WGS84;
>         boolean lenient = true; // allow for some error due to different
> datums
>         MathTransform transform = CRS.findMathTransform(srcCRS, destCRS,
> lenient);
>         return JTS.transform(source, transform); //EXCEPTION HERE!!! See
> the
> trace at the end of post
>     }
>
>
> @Test
>     public void drawRetailStoreMC7700001() throws ParserException,
> IOException, FactoryException, TransformException {
>         * //read source data*
>         List<GSMCellLocation> gsmCellLocations =
> GeoDataSampleHelper.readGSMCellLocationFromMoscowRegion();
>         RetailStore retailStore =
> GeoDataSampleHelper.readRetailStoreByCode(MC7700001);
>         GeoPoint storeGeoPoint =
> retailStore.getStoreLocation().getGeoPoint();
>
>         List<Geometry> geometryList = new LinkedList<Geometry>();
>
>         GeometricShapeFactory gsFactory = new GeometricShapeFactory();
>         gsFactory.setCentre(transformToPlanar(new
> Coordinate(storeGeoPoint.getLongitude(),
>
> storeGeoPoint.getLatitude())));
>         gsFactory.setSize(200);
>         Geometry storeCircle = gsFactory.createEllipse();
> *   //find intersection between circle and sectors*
>         for(GSMCellLocation cellLoc : gsmCellLocations){
>             gsFactory = new GeometricShapeFactory();
>             gsFactory.setCentre(transformToPlanar(new
> Coordinate(cellLoc.getGeoPoint().getLongitude(),
>
> cellLoc.getGeoPoint().getLatitude())));
>             gsFactory.setSize(cellLoc.getMidDist() * 2);
>             Geometry cellSector =
> gsFactory.createArc(cellLoc.getStartAngle(), cellLoc.getAngleWidth());
>
>             if(cellSector.intersects(storeCircle)){
>                 geometryList.add(cellSector);
>             }
>         }
>         LOG.info("geometryList.size {}",geometryList.size());
>
> *//prepare output*
>         Encoder encoder = new Encoder(new KMLConfiguration());
>         encoder.setIndenting(true);
>
>         SimpleFeatureTypeBuilder typeBuilder = new
> SimpleFeatureTypeBuilder();
>         typeBuilder.setName("poi");
>         typeBuilder.add("geometry", Polygon.class,
> DefaultGeographicCRS.WGS84);//DefaultGeographicCRS.WGS84);
>
>         SimpleFeatureType TYPE = typeBuilder.buildFeatureType();
>
>
>         DefaultFeatureCollection features  = new
> DefaultFeatureCollection("test",TYPE);
> *//output first 10 sectors*
>         for(int i=0; i<10; i++){
>             SimpleFeatureBuilder featureBuilder = new
> SimpleFeatureBuilder(TYPE);
>             featureBuilder.add( transformToGeo(geometryList.get(i)));
> *//EXCEPTION HERE transformToGeo*
>             SimpleFeature simpleFeature =
> featureBuilder.buildFeature(String.valueOf(i + 1));
>             features.add( simpleFeature );
>         }
>         encoder.encode(features, KML.kml, System.out);
>
>     }
>
> ava.lang.AssertionError: NaN
>         at
>
> org.geotools.referencing.operation.transform.GeocentricTransform.inverseTransform(GeocentricTransform.java:438)
>         at
>
> org.geotools.referencing.operation.transform.GeocentricTransform.inverseTransform(GeocentricTransform.java:338)
>         at
>
> org.geotools.referencing.operation.transform.GeocentricTransform$Inverse.transform(GeocentricTransform.java:546)
>         at
>
> org.geotools.geometry.jts.DefaultCoordinateSequenceTransformer.transform(DefaultCoordinateSequenceTransformer.java:123)
>         at
>
> org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.projectCoordinateSequence(GeometryCoordinateSequenceTransformer.java:247)
>         at
>
> org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transformLineString(GeometryCoordinateSequenceTransformer.java:210)
>         at
>
> org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transform(GeometryCoordinateSequenceTransformer.java:152)
>         at org.geotools.geometry.jts.JTS.transform(JTS.java:436)
> It happens on the mentioned line
>
>
>
> --
> View this message in context:
> http://osgeo-org.1560.n6.nabble.com/WGS84-to-a-Cartesian-transformation-tp4318606p5034341.html
> Sent from the geotools-gt2-users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013
> and get the hardware for free! Learn more.
> http://p.sf.net/sfu/sophos-d2d-feb
> _______________________________________________
> GeoTools-GT2-Users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to