![]() ![]() Return new PointF(Convert.ToSingle(x), Convert.ToSingle(y)) Math.Log((1d + f) / (1d - f)) * -this.YPixelsToRadiansRatio) Math.Sin(coordinates.Y * RadiansToDegreesRatio), + (coordinates.X * this.XPixelsToDegreesRatio)) Public PointF FromCoordinatesToPixel(PointF coordinates) Var halfPixelGlobeSize = Convert.ToSingle(pixelGlobeSize / 2d) This.YPixelsToRadiansRatio = pixelGlobeSize / (2d * Math.PI) This.XPixelsToDegreesRatio = pixelGlobeSize / 360d Var pixelGlobeSize = this.PixelTileSize * Math.Pow(2d, zoomLevel) Public GoogleMapsAPIProjection(double zoomLevel) Private readonly double YPixelsToRadiansRatio Private readonly double XPixelsToDegreesRatio Private readonly PointF PixelGlobeCenter Private readonly double RadiansToDegreesRatio = Math.PI / 180d Private readonly double DegreesToRadiansRatio = 180d / Math.PI Private readonly double PixelTileSize = 256d I have the C# source code for this: public class GoogleMapsAPIProjection You will have to implement the Google Maps API projection in your language. p.x and p.y are now EPSG:3785 in meters ansform(source, dest, p) //do the transformation. Var p = new Proj4js.Point(-76.0,45.0) //any object will do as long as it has 'x' and 'y' properties Var dest = new Proj4js.Proj('EPSG:3785') //destination coordinates in meters, global spherical mercators projection, see ![]() Var source = new Proj4js.Proj('EPSG:4326') //source coordinates will be in Longitude/Latitude, WGS84 once initialized, these may be re-used as often as needed creating source and destination Proj4js objects You can use the proj4js library like this: // include the library Transform spherical Mercator coordinate into image pixel coordinate using the linear relationship discovered above.This can be done using the proj4js library. Project lat/lon to spherical Mercator.In order to go from a WGS84 point to a pixel on the image, the procedure is now: You can safely do a simple linear transform to convert between points on the image, and points on the earth in the spherical Mercator projection, and back again.There conversion tools out there, my favorite is to use the cs2cs tool that is part of the PROJ4 project. Convert the WGS lat/longs to the spherical Mercator projection.Find the WGS84 lat/long of the corners of the image.This enables you to do the conversion using the following procedure: This means, for every lat/long coordinate there is a matching meter/meter coordinate. The spherical Mercator projection defines a coordinate pair in meters, for the surface of the earth. I'm assuming your data is in these coordinate systems. The most common GCS, used in most web-mapping applications and for GPS's, is WGS84. This can vary, because there are different ways of locating lat/longs on the globe. The geographic coordinate system your latitude/longitude coordinates are using.If they are purely derived from Google Maps, then chances are they are using a spherical Mercator projection. In order to achieve your goal, you first must know two things about your data: As others have pointed out, the cause of the distortion is the fact that the spherical (or more accurately ellipsoidal) earth is projected onto a plane. The key to all of this is understanding map projections. gif, in which I must draw a point corresponding geographic coordinates. I do not use API Google Maps, I have only: geographic coordinates of the object (they are from google maps), I still have at my site a simple picture *. How to solve a problem on country scales? I know that on small scales (for example on city scales) it to make simply enough (it is necessary to learn what geographic coordinates has one of picture corners, then to learn "price" of one pixel in geographic coordinates on a picture on axes OX and OY separately).īut on the big scales (country scale) "price" of one pixel will be not a constant, and will vary strongly enough and the method described above cannot be applied. Ideally I can do this in Javascript, but PHP would be OK. Problem: How do I convert GPS coordinates from various data points we have into pixel coordinates in the image? We modified a Google Maps image with some artistic elements, but the relation between GPS coordinates and pixels remains the same.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |