I'm using this example to import a polygon on an Openlayer map. However I'm having issues with the coordinate formatting. I'm importing the coordinates with a space as the delimiter with a carriage return between lines. I achieve success with a set of example coordinates from the Openlayers example. E.g. -
-5e6 6e6
-5e6 8e6
-3e6 8e6
-3e6 6e6
-5e6 6e6
This format works as it does in the example. However, when I use decimal degree format with the exact code that the examples uses this doesn't work. E.g. -
-83.6743 43.5857
-83.6743 44.0603
-82.4072 44.0603
-82.4072 43.5857
-83.6743 43.5857
Any suggestions would be appreciated.
Usually you would not want your view in EPSG:4326, so you transform the data from EPSG:4326 projection to display features in the view projection (which is usually EPSG:3857) as in https://openlayers.org/en/latest/examples/wkt.html
In the example by OpenLayers the Web Mercator Projection is used. You can see this from the key crs in geojsonObject:
'crs': {
'type': 'name',
'properties': {
'name': 'EPSG:3857',
},
},
"EPSG:3857" is the code for Web Mercator projection.
However, your coordinates are in the reference system WGS84 (code: "EPSG:4326"). Thus, you need to replace in the example "EPSG:3857" by "EPSG:4326". In addition, you have to adapt center and zoom in new View().
Related
I want to use long/lat (EPSG:4326) coordinates in a bokeh plot and have a map in the Background.
I tried with the tile provider maps as suggested in bokeh: Mapping geo data.
But the format is in web mercator coordinates (EPSG:3857) and I don't want to convert my coordinates.
The general question how to do this is unanswered in Is it possible to set figure axis_type in bokeh to geographical (long/lat)?
My idea was to use extra axes:
from bokeh.plotting import figure, show
from bokeh.models import Range1d, LinearAxis
from bokeh.tile_providers import CARTODBPOSITRON, get_provider
tile_provider = get_provider(CARTODBPOSITRON)
p = figure(x_range=(-180, 180), y_range=(-90, 90)) # EPSG:4326
# add extra axis
p.extra_x_ranges = {"EPSG:3857x": Range1d(start=-20026376.39, end=20026376.39)}
p.extra_y_ranges = {"EPSG:3857y": Range1d(start=-20048966.10, end=20048966.10)}
# place extra axis
p.add_layout(LinearAxis(x_range_name="EPSG:3857x"), 'above')
p.add_layout(LinearAxis(y_range_name="EPSG:3857y"), 'right')
p.add_tile(tile_provider, x_range_name="EPSG:3857x", y_range_name="EPSG:3857y")
show(p)
But the map is not visible.
Is there a way to use extra axis for a tile_provider?
If you are just asking about displaying lat/lng visually on the axes, then all you have to do is set the axis type to "mercator"
p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000),
x_axis_type="mercator", y_axis_type="mercator")
This is demonstrated on the documentation page you linked.
If you are asking about using data that is in lan/lng coordinates to plot on a tile plot, then you will need to convert it to Web Mercator first. The underlying coordinate system for tiles is always Web Mercator.
If you are asking about something else, then your question is not clear (please update to clarify).
I am drawing one line from Location A to Location B using React.JS with Open Layers. I wish to get the Latitude and Longitude of the Location A and Location B.
I have added one listener after draw completion. But it is giving the co-ordinates as below . How can I get the latitude and longitude?
Listener:
draw.on('drawend',function(e){
console.log("Co Ordinates :",e.feature.getGeometry())
//console.log("Co Ordinates :",e.feature.getGeometry().getExtent())
});
Console :
Extent and flat coordinates values are printed in console as below
extent_:(4) [8732987.679175382, 1920132.5190330548, 8735555.9637923, 1920254.817578509]
flatCoordinates:(4) [8732987.679175382, 1920132.5190330548, 8735555.9637923, 1920254.817578509]
If you are just looking for a way to convert the coordinates you can use ol.proj.transform(coordinate, source, destination)
Using this
ol.proj.transform([8732987.679175382, 1920132.5190330548], 'EPSG:3857', 'EPSG:4326')
Will give this as output
[78.44976308230713, 16.99405070970775]
Also note that you can use getFirstCoordinate and getLastCoordinate methods on the line feature to get the first and last coordinates.
OpenLayer is working on different location formats like EPSG: 3857, EPSG: 4285 etc.
There are some Transform/Projection api enter link description here
Use this api's and transfer your locations to your desired formats
I have spent dozens of hour trying to find is it possible to change projection with mapserver with no luck so far. My input format is EPSG 3067 and I need to convert it to EPSG 900913 for Google Map use.
In the MAP object add
PROJECTION "init=epsg:900913" END
this sets the output projection of the map. Then in t LAYER object add
PROJECTION "init=epsg:3067" END
this set the projection that the incoming data for the layer is already in.
You will also need to add the following line to your /usr/share/proj/epsg or the equivalent path if you are on Windows:
Spherical Mercator projection
<900913> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +over +nadgrids=#null +no_defs <>
Do my tiles need to adhere to any particular specs?
I have a large image file which I'd like to turn into a map with LeafletJS. I am going to be using the Python Imaging Library to cut it up into all the various tiles I need.
However, I can't find any information about using custom maps in Leaflet. Do I provide Leaflet with the range of X,Y,Z info somehow? Do I give it the pixel size of each tile? Does it figure this out on its own?
To put my question into one concise question: What do I need to do in order to have image files that can double as map tiles with LeafletJS, and what, if anything, do I need to do in my front-end script? (beyond the obvious specifying of my custom URL)
You are looking for a TileLayer. In this TileLayer, you give the URL for the to-be-fetched images to leaflet with a template like this:
http://{s}.somedomain.com/blabla/{z}/{x}/{y}.png
When you are at the specified zoom, x and y level, Leaflet will automatically fetch the tiles on the URL you gave.
Depending on the image you want to show, the bigger part of the work will however be in the tile generation. Tiles by default have a 256x256px size (can be changed in the TileLayer options), and if you are using geodata the used projection is Mercator projection. It may take some time to get the tile ids right. Here is an example on how the tile ids work.
You can even serve tiles directly from a database.
The format leaflet specifies is very flexible.
Leaflet just uses the z,x,y place holders to request specific tiles.
For example:
L.tileLayer('http://localhost/tileserver/tile.aspx?z={z}&x={x}&y={y}', {
minZoom: 7, maxZoom: 16,
attribution: 'My Tile Server'
}).addTo(map);
where Tiles.aspx
Option Strict On
Partial Class tile
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim z, x, y As Integer
z = CInt(Request.QueryString("z"))
x = CInt(Request.QueryString("x"))
y = CInt(Request.QueryString("y"))
Dim b() As Byte = DB.GetTile(z, x, y)
Response.Buffer = True
Response.Charset = ""
'Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "image/png"
Response.AddHeader("content-disposition", "attachment;filename=" & y & ".png")
Response.BinaryWrite(b)
Response.Flush()
Response.End()
End Sub
I'm trying to use kml for rendering geo-coordinates in google maps.
Unfortunately, I have some troubles with coordinates: when I insert in KML coordinates from Google maps, and then pass this KML file to google maps service, placemarks points to another place in the Earth.
Maybe I dont guess format of placemark location for KML ?
Sometimes Google Maps will report coordinates in "Degrees, Minutes, Seconds" (DMS) notation, which can look like this: 37°48'21.0"N 122°27'57.6"W.
KML needs coordinates in "Decimal Degrees" (DD) notation, which would look like this: -122.466001, 37.805828. Note that KML also expects the order Longitude, Latitude, which is different from many other places, which show Latitude then Longitude.
So... if you're somehow getting your coordinates in DMS notation, then you'll need to convert to DD notation, and make sure the Lon,Lat order is correct.
in the KML file i have the LatLng was backwards.
KML => -.709448,54.009222,0
gmaps => 54.009222,-.709448
use pandas to read cvs into df
then use simplekml to export it into lml
Note: coords is (lon,lat,height) # lon, lat, optional height
example:
import simplekml
snet_kml='test.kml'
kml = simplekml.Kml()
for name,lat,lon,height in zip(snet[NAMES[0]], snet[NAMES[1]], snet[NAMES[2]], snet[NAMES[3]]):
kml.newpoint(name=name, coords=[(lon,lat,height)]) # lon, lat, optional height
print("*** Created {}".format(snet_kml))
print(kml.kml())
kml.save(snet_kml)