1

I am new to GIS and have a problem with using geo-coordinates which I got from Google. I have some lat, lng data in my database(MSSQL) which I obtained from Google API (I think it should be in 3857 format), however, I needed to create a layer in GeoServer, so I created a view as

   geometry::STGeomFromText('Point(' + CAST(dp.lat AS nvarchar(50)) + ' ' + CAST(dp.lng AS nvarchar(50)) + ')', 3857) AS Expr1

In Geoserver, when adding a layer I use the following setting which I believe there is something wrong with it and I am not sure which Compute shall I click and in what order. enter image description here

In the publishing, I also select point as default style.

and finally in leafLet

 var mywms = L.tileLayer.wms("http://localhost:9090/geoserver/localhost/wms", {
        layers: 'localhost:DP_View',
        format: 'image/png',
        transparent: true,
        version: '1.1.0'
         ,SrsName: 'EPSG:3857'
    });
    mywms.addTo(map);

They either sit in the middle or on top of the map.

1
  • Thank you to both of you, Alex and Stephen, both of the answer were excellent. The only missing points in your answers is that the order is long/lat as I mentioned. I upvoted both of your answers and much appreciated that. Jun 22 '17 at 7:51
5

I have some lat, lng data which I obtained from Google API (I think it should be in 3857 format)

That's the first source of confusion. EPSG 3857 corresponds to Web Mercator (which uses metres). This is the coordinate reference system used on Google Maps, Leaflet, Bing Maps and ArcGIS.

However, lat/long data corresponds to EPSG 4326 (which uses decimal degrees).

So if your dataset uses lat/long, you should specify EPSG 4326 as the Native SRS in GeoServer.

You can optionally specify the Declared SRS to be EPSG 3857 if you want GeoServer to re-project your data to Web Mercator, but this isn't necessary to use the layer in Leaflet, as Leaflet and GeoServer will work together to perform the conversion on-the-fly.

See https://gis.stackexchange.com/a/48952/3112 for a good explanation of these coordinate systems, and http://docs.geoserver.org/stable/en/user/data/webadmin/layers.html for an explanation of Native vs Declared reference systems.

3
  • Thank you Stephen, Yes that was one of the issue as I mentioned. I just Solved it a minute ago, so happy, thank you for your time both yesterday and today Jun 20 '17 at 23:36
  • Ah, you beat me by 2 minutes!
    – Alex Leith
    Jun 20 '17 at 23:36
  • 1
    @AlexLeith between us we have a half-decent answer ;) Jun 20 '17 at 23:50
4

Latitude and Longitude coordinates from Google will not be EPSG:3857. They will be WGS84, which is EPSG:4326 (or close enough).

On GeoServer, make sure your native CRS is EPSG:4326, and then remove the line about CRS on Leaflet and you should be good to go. (The EPSG:3857 CRS is the default for Leaflet, and it knows how to ask GeoServer for it.)

(By the way, you can tell that your coordinates are lat/lon, because the bounding box that GeoServer created is in the range -90 to 90 and -180 to 180, whereas the EPSG:3857 CRS has coordinates like 8604109.091324, -5160390.222646.)

0
1

Took me a while but found the problem. GeoServer needs data in the format of long lat not lat long, so the query should be

 geometry::STGeomFromText('Point(' + CAST(dp.lng AS nvarchar(50)) + ' ' + CAST(dp.lat AS nvarchar(50)) + ')', 4326) AS Expr1

And for the GeoServer leaves the Native and declared the same 4326, LeafLet converts it to the appropriate format automatically 3857

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.