From: Juan D. <jua...@gm...> - 2013-06-15 23:28:10
|
Hi sorry for the late reply I have had my hands full and I wanted to test the code. Anyways this is my code double lat, lon; lat = Double.parseDouble(ubicacionDM.getUbicacion() .getVerbatLatitudUbicacion()); lon = Double.parseDouble(ubicacionDM.getUbicacion() .getVerbatLongitudUbicacion()); System.out.println("Lat: " + lat + " Lon:" + lon); Coordinate c = new Coordinate(lat, lon); GeometryFactory gf = new GeometryFactory(); Point p = gf.createPoint(c); CoordinateReferenceSystem utmCrs = CRS.decode("EPSG:3857"); CoordinateReferenceSystem codigoEPSG = CRS.decode("EPSG:"+ubicacionDM.getUbicacion().getZona().getEpsgZona()); MathTransform mathTransform1 = CRS.findMathTransform(CRS.decode("EPSG:32717"), CRS.decode("EPSG:3857")); Point p1 = (Point) JTS.transform(p, mathTransform1); System.out.println(p1.getCoordinate()); When I do this get this Lat: 815612.0 Lon:9948458.0 (-8701259.838602547, -51846.7213966133, NaN) They should be close to these values (-0.4544682953,-78.1736736245), where is my mistake. In another forum someone pointed me that I should convert from UTM to latitude,longitude and latitude,longitude to EPSG:3857 On Thu, Jun 6, 2013 at 12:49 AM, Ben Caradoc-Davies < Ben...@cs...> wrote: > As far as I can tell, the example does what was asked for first > (Google->WGS84) but not what was asked for second in the clarification > (Google->WGS84/UTM), which is entirely different. That code appears to > convert from Google eastings/northings to WGS84 latitude/longitude. I have > not tested it, but I expect that, to convert from WGS 84 / UTM Zone 17S > (EPSG:32717) eastings/northings in metres to Google Spherical Mercator > (EPSG:3857) eastings/northings in metres you should use: > > CRS.findMathTransform(CRS.**decode("EPSG:32717"), CRS.decode("EPSG:3857")) > > Be sure to test it! > > Note that both these CRS are in eastings/northings in metres, not > latitude/longitude. See also the discussion here: > http://docs.openlayers.org/**library/spherical_mercator.**html<http://docs.openlayers.org/library/spherical_mercator.html> > > Kind regards, > Ben. > > > On 06/06/13 13:33, Juan Diego wrote: > >> Thanks, I know understand a little bit better about the codes, but here >> is my confusion in the following code >> >> public static void main(String[] args) throws FactoryException, >> TransformException { >> GeometryFactory gf = new GeometryFactory(); >> Coordinate c = new Coordinate(175784.99999999997, 5842215.0); >> >> Point p = gf.createPoint(c); >> >> CoordinateReferenceSystem utmCrs = CRS.decode("EPSG:3785"); >> MathTransform mathTransform = CRS.findMathTransform(utmCrs, >> DefaultGeographicCRS.WGS84, false); >> Point p1 = (Point) JTS.transform(p, mathTransform); >> >> System.out.println(p1.**getCoordinate()); >> >> } >> >> Where is he setting the code for the zone, if I wanted to use 32717, how >> do I set the zone in mathTransform. >> >> >> >> On Thu, Jun 6, 2013 at 12:22 AM, Ben Caradoc-Davies >> <Ben...@cs... <mailto:Ben.Caradoc-Davies@**csiro.au<Ben...@cs...>>> >> wrote: >> >> Juan, >> >> each UTM zone has a separate EPSG code: >> http://spatialreference.org/__**ref/epsg/32612/<http://spatialreference.org/__ref/epsg/32612/> >> >> <http://spatialreference.org/**ref/epsg/32612/<http://spatialreference.org/ref/epsg/32612/> >> > >> >> The codes follow the pattern: >> >> WGS 84 / UTM Zone xxN is: >> http://spatialreference.org/__**ref/epsg/326xx/<http://spatialreference.org/__ref/epsg/326xx/> >> >> <http://spatialreference.org/**ref/epsg/326xx/<http://spatialreference.org/ref/epsg/326xx/> >> > >> >> WGS 84 / UTM Zone xxS is: >> http://spatialreference.org/__**ref/epsg/327xx/<http://spatialreference.org/__ref/epsg/327xx/> >> >> <http://spatialreference.org/**ref/epsg/327xx/<http://spatialreference.org/ref/epsg/327xx/> >> > >> >> The preferred EPSG code for Google Spherical Mercator is now >> EPSG:3857. See this discussion: >> http://wiki.openstreetmap.org/**__wiki/EPSG:3857<http://wiki.openstreetmap.org/__wiki/EPSG:3857> >> >> <http://wiki.openstreetmap.**org/wiki/EPSG:3857<http://wiki.openstreetmap.org/wiki/EPSG:3857> >> > >> >> Kind regards, >> Ben. >> >> >> On 06/06/13 11:46, Juan Diego wrote:http://docs.openlayers.** >> org/library/spherical_**mercator.html<http://docs.openlayers.org/library/spherical_mercator.html> >> >> I was reading this >> http://osgeo-org.1560.x6.__nab**ble.com/convert-wgs84-__** >> coordinate-to-Google-Map-__**coordinate-system-EPSG-3785-__** >> with-geotools-and-java-__**td4983362.html<http://nabble.com/convert-wgs84-__coordinate-to-Google-Map-__coordinate-system-EPSG-3785-__with-geotools-and-java-__td4983362.html> >> <http://osgeo-org.1560.x6.**nabble.com/convert-wgs84-** >> coordinate-to-Google-Map-**coordinate-system-EPSG-3785-** >> with-geotools-and-java-**td4983362.html<http://osgeo-org.1560.x6.nabble.com/convert-wgs84-coordinate-to-Google-Map-coordinate-system-EPSG-3785-with-geotools-and-java-td4983362.html> >> >, >> >> >> In the example given above by guziy >> <http://osgeo-org.1560.x6.__na**bble.com/template/__** >> NamlServlet.jtp?macro=user___**nodes&user=219523<http://nabble.com/template/__NamlServlet.jtp?macro=user___nodes&user=219523> >> >> <http://osgeo-org.1560.x6.**nabble.com/template/** >> NamlServlet.jtp?macro=user_**nodes&user=219523<http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=219523> >> >>, >> >> in which line is he setting the zone and the hemisphere, he >> talks about >> setting UTM 12N, but I dont know how to set the code from each >> zone. >> >> Thanks, >> >> >> >> >> ------------------------------**__----------------------------** >> --__------------------ >> >> How ServiceNow helps IT people transform IT departments: >> 1. A cloud service to automate IT design, transition and >> operations >> 2. Dashboards that offer high-level views of enterprise services >> 3. A single system of record for all IT processes >> http://p.sf.net/sfu/__**servicenow-d2d-j<http://p.sf.net/sfu/__servicenow-d2d-j> >> <http://p.sf.net/sfu/**servicenow-d2d-j<http://p.sf.net/sfu/servicenow-d2d-j> >> > >> >> >> >> ______________________________**___________________ >> GeoTools-GT2-Users mailing list >> GeoTools-GT2-Users@lists.__sou**rceforge.net<http://sourceforge.net> >> <mailto:GeoTools-GT2-Users@**lists.sourceforge.net<Geo...@li...> >> > >> https://lists.sourceforge.net/**__lists/listinfo/geotools-gt2-** >> __users<https://lists.sourceforge.net/__lists/listinfo/geotools-gt2-__users> >> >> <https://lists.sourceforge.**net/lists/listinfo/geotools-** >> gt2-users<https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users> >> > >> >> >> -- >> Ben Caradoc-Davies <Ben...@cs...> >> Software Engineer >> CSIRO Earth Science and Resource Engineering >> Australian Resources Research Centre >> >> >> > -- > Ben Caradoc-Davies <Ben...@cs...> > Software Engineer > CSIRO Earth Science and Resource Engineering > Australian Resources Research Centre > |