Hi, i comment my solution for display the coordinate when mouse move.
i use the following:
CoordinateOperationFactory coFactory =
FactoryFinder.getCoordinateOperationFactory(null);
MathTransform trans = null;
CoordinateFilter transFilter = null;
CoordinateReferenceSystem crsCoordenada = DefaultGeographicCRS.WGS84;
MathTransformFactory mtFactory =
FactoryFinder.getMathTransformFactory(null);
trans = mtFactory.createParameterizedTransform(parameters);
when mouse move calculate the coordinate:
ReferencedEnvelope referencedEnvelope = getContext().getAreaOfInterest();
double width = referencedEnvelope.getWidth();
double height = referencedEnvelope.getHeight();
double width2 = referencedEnvelope.getWidth() / 2.0;
double height2 = referencedEnvelope.getHeight() / 2.0;
double mapX = ((x * width) / (double) bounds.getWidth()) +
referencedEnvelope.getMinX();
double mapY = (((bounds.getHeight() - y) * height) / (double)
bounds.getHeight())
+ referencedEnvelope.getMinY();
then apply the transform:
CoordinateOperation co =
coFactory.createOperation(referencedEnvelope.getCoordinateReferenceSystem(),
crsCoordenada);
transFilter = new
TransformationCoordinateFilter(co.getMathTransform());
Coordinate coor = new Coordinate(mapX, mapY);
Point pointCoor = geomFac.createPoint(coor);
pointCoor.apply(transFilter);
LepiMarbois wrote:
>
> Dear All,
> I would like to get the position in lat/long (WGS84 ) of a point from a
> map displayed in various projections (WGS84, Lambert, Mercator ).
> I am getting strange results with the code below.
> With a map of France displayed entirely on the screen I am getting
> errors from nearly 0.5 degree, while if I zoom I am getting errors of
> few minutes .
> That even if I modify the lenient parameter or sampling envelope points
> in :
> ReferencedEnvelope worldwg84 = env.transform(
> Projections.getCRS(Projections.WGS84), true,20);
> Is the code I am using wrong, is there a solution to get a better
> accuracy ?
> Best regards,
> Pierre
>
> Version used Geotools 2.4.4
>
> CRS build with the following data :
> WGS84 = "GEOGCS[\"WGS84\", DATUM[\"WGS84\", SPHEROID[\"WGS84\",
> 6378137.0, 298.257223563]], PRIMEM[\"Greenwich\", 0.0],
> UNIT[\"degree\",0.017453292519943295], AXIS[\"Longitude\",EAST],
> AXIS[\"Latitude\",NORTH]]";
>
> LambertFrance =
> "PROJCS[\"France_II\",GEOGCS[\"GCS_NTF_Paris\",DATUM[\"Nouvelle_Triangulation_Francaise\",SPHEROID[\"Clarke_1880_IGN\",6378249.2,293.46602]],PRIMEM[\"Paris\",2.337229166666667],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"False_Easting\",600000],PARAMETER[\"False_Northing\",2200000],PARAMETER[\"Central_Meridian\",0],PARAMETER[\"Standard_Parallel_1\",45.898918964419],PARAMETER[\"Standard_Parallel_2\",47.696014502038],PARAMETER[\"Latitude_Of_Origin\",46.8],UNIT[\"Meter\",1]]";
>
>
>
> Mercator = "PROJCS[\"WGS84+GRS80 / Mercator\",GEOGCS[\"WGS
> 84\",DATUM[\"WGS_1984\",SPHEROID[\"GRS
> 1980\",6378137,298.257222101],TOWGS84[0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Decimal_Degree\",0.0174532925199433]],PROJECTION[\"Mercator_1SP\"],PARAMETER[\"central_meridian\",0],UNIT[\"Meter\",1]]";
>
>
>
>
> public void mouseMoved(MouseEvent e) {
> try
> {Point2D pntécran = (Point2D) e.getPoint();
> ReferencedEnvelope env = m_context.getAreaOfInterest();
> ReferencedEnvelope worldwg84 = env.transform(
> Projections.getCRS(Projections.WGS84), true,20);
> // true: lenient parameter
> AffineTransform world2screen = RendererUtilities.worldToScreenTransform(
> worldwg84, m_mapPane.getBounds(),Projections.getCRS(Projections.WGS84));
> AffineTransform screen2world2 = world2screen.createInverse();
> Point2D res = screen2world2.transform(pntécran,null);
> m_statusBar.setMessage(Util.to_Latitude(res.getY())+ " , " +
> Util.to_Longitude(res.getX()));
> }
> catch (NoninvertibleTransformException ex)
> {System.out.println ("erreur transformlecture feature source " +ex);
> }
> …..
>
>
> -------------------------------------------------------------------------
> 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
>
>
--
View this message in context:
http://n2.nabble.com/Accuracy-of-screen-to-world-position-transformations-tp1942552p2132147.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users