How to use bbox in long/lat with google/bing/etc… using mapserver‏ - google-maps

The bbox of OpenLayers.Control.GetFeature works in utm when the baselayer is 900913 ie. google/bing/etc) and in long/lat when the baselayer is 4326 (ie. my postgis layers served by mapserver), no matter what overlays them. This is what openlayers says.
So, how can I force bbox to be in long/lat when I use one of my layers over google for example? I do want the bbox being in long/lat rather than 900913 (ie. using baselayer projection). I've read many webs about this but with geoserver, some posts about mapserver say that both EPSG:900913 and EPSG:4326 must be set in METADATA, I changed that and also assigned "srs" and "projection" (with the appropriate expression) in my layers (and in protocols) but with no effect in bbox at all. What else could I try?
Any idea will be appreciated, thanks in advance,
Gery

To solve this problem is necessary to use prototype with OpenLayers.Control.GetFeature and then use .transform with epsg4326 and epsg900913, a bit more info about here: OpenLayers.Class with OpenLayers.Control.GetFeature

Related

Openlayers GIS - Georeferenced DEM(GeoTIFF) not positioned correctly in Map (OpenStreetMap)

With Openlayers, I'm visualizing GIS rasters(DEM, Orthomosaic) in GeoTIFF format(using WebGLTileLayer) on top of OSM(as WebGLTile layer) in OL Map.
The issue I'm having is, the GIS rasters which have georeferencing, are not positioned in its correct geographic position on the OSM base map. The DEM seems to appear in nowhere, around gulf areas or on top of water bodies.
I've created OSM layer with it's default projection & I'm setting view after raster source is loaded, using source.getView()
I referred to Raster reprojection examples in the Openlayers website, but wasnt able to solve this.
Does anyone have an idea on how to resolve this?
As Mike had suggested in the comments, this issue was happening since even though the projection name was identified from the raster - Eg: "EPSG:3237", the Openlayers library doesnt have the projection definition(what it actually means), so now I'm fetching proj definition from epsg.io & registering in proj4 defs. Now it works perfectly!
Thanks Mike.

Generate overlay map image from geo data

I need to generate a transparent image to apply on map similar to these:
Image_1or Image_2
I need to generate this image from a dataset: I have many data points (with lat and long) and I would to generate this image (server side) to show density on map of my data.
Know you something (libraries, or best way to solve my problem) about it?
Those are heatmaps. Google Maps already has this capbility, so you should check out their sample and the documentation. It can be as basic as loading in your data points and applying them as a layer or you can do much more customization.

Google maps search by address component

I have implemented a basic google places autocomplete in my web app, for example saying "Heraclion, Crete" and it translates it to the latlng coordinates that I want. I also used the mysql radius example from the api to show nearest entries. I also have locations in a second area of Crete, called "Rethymnon".
The problem now is the following. Supposedly one types just Crete. How can I get all the entries from Heraclion and Rethymnon? My code uses the radius approach as mentioned before. So I need something else to define it in a rectangular area.
Is this possible?
If the result contains a viewport (LatLngBounds), you could use that.
PlaceResult
geometry: The Place's geometry-related information. This includes:
location provides the latitude and longitude of the Place.
viewport defines the preferred viewport on the map when viewing this Place

Horseshoe shaped polygon

I have the following kml polygon:
<Polygon><outerBoundaryIs><LinearRing><coordinates>20.002,80.002 20,80.002 20,80.004 20.006,80.004 20.006,80.001 20.002,80.001 20.002,80.002 20.004,80.002 20.004,80.003 20.002,80.003 </coordinates></LinearRing></outerBoundaryIs></Polygon>
If I view this polygon in a cell in my fusion table, in the Table View of Google Fusion Maps, it looks like this:
However, in the actual google map, in the Map View, it looks like this:
The duplicate point has been rather annoyingly dropped. I want what's shown in the first diagram above, but how should I change my polygon to get the same shape in google maps?
I also tried with an inner bound, but no luck there either:
<Polygon><outerBoundaryIs><LinearRing><coordinates>20.002,80.002 20,80.002 20,80.004 20.006,80.004 20.006,80.001 20.002,80.001 20.002,80.002 20.004,80.002 20.004,80.003 20.002,80.003 </coordinates></LinearRing></outerBoundaryIs></Polygon>
Thanks,
Barry
Self-intersecting polygons require quite a bit of extra power to draw correctly, so they are not widely supported in all 2d rendering APIs / implementations.
I suggest you work around the problem by splitting your polygon into two pieces.
Ok, I think I have the answer. I can add a tiny offset (jitter) to one of the two duplicate points in the polygon. However I must add the jitter in the correct direction otherwise the polygon becomes invalid and google no longer draws it. Looking at the previous points in the polygon loop, I should be able to establish in which direction I need to apply the jitter in.
<Polygon><outerBoundaryIs><LinearRing><coordinates>20.002,80.002 20,80.002 20,80.004 20.006,80.004 20.006,80.001 20.002,80.001 20.002000001,80.002 20.004,80.002 20.004,80.003 20.002,80.003 </coordinates></LinearRing></outerBoundaryIs></Polygon>

Around-the-world path breaking in Google Static Maps

I'm creating Google Static Maps with a path between markers and have come across certain coordinate combinations that break the path.
The path breaks in this example (markers # Beijing, SF, NY, Azores, Rome):
http://maps.google.com/maps/api/staticmap?path=color:0xff0000cc|weight:3|39.904214,116.407413|37.77493,-122.419416|40.714353,-74.005973|38.721642,-27.220577|41.89052,12.494249&markers=39.904214,116.407413|37.77493,-122.419416|40.714353,-74.005973|38.721642,-27.220577|41.89052,12.494249&maptype=terrain&sensor=false&size=640x404
And works in this example (marker # Rome removed)
http://maps.google.com/maps/api/staticmap?path=color:0xff0000cc|weight:3|39.904214,116.407413|37.77493,-122.419416|40.714353,-74.005973|38.721642,-27.220577&markers=39.904214,116.407413|37.77493,-122.419416|40.714353,-74.005973|38.721642,-27.220577&maptype=terrain&sensor=false&size=640x404
The cause is not crossing over the Greenwich Meridian as I initially thought. It breaks even if I add a marker before that, seemingly any a point East of the automatically calculated centerpoint of the map...but only when the path starts on the other side of -180 longitude.
To prove that, you can see that the Beijing, SF, NY, Azores, Rome path displays correctly when I set the map centerpoint to -170,35
http://maps.google.com/maps/api/staticmap?path=color:0xff0000cc|weight:3|39.904214,116.407413|37.77493,-122.419416|40.714353,-74.005973|38.721642,-27.220577|41.89052,12.494249&markers=39.904214,116.407413|37.77493,-122.419416|40.714353,-74.005973|38.721642,-27.220577|41.89052,12.494249&maptype=terrain&sensor=false&size=640x404&center=-170,35
Unfortunately, I can't programmatically set center like this because I never know the collection of points I'm going to get, and it would be next to impossible to detect that the passed points would cause a line break.
Any ideas?
First: you can calculate the center even if you don't know the collection of points (locations) at compile time: at runtime you know all the points (otherwise it would be not possible to insert the coordinates into the URL), therefore you can easily iterate over all the points and compute the center. You can computing the average of all coordinates and you get the geometric center (also called centroid): this is the easier way. Another way to do is to check the most distant pair of locations (for both, latitude and longitude) and then set the middle point as center: this requires slightly more coding (for instance to compute the longitude distance you need to take into account the you have to compute the distance in two directions, since it is possible to go 'around the world) and it has an higher complexity.
I don't go deeper in this topic because, even if you compute correctly the center of your points, this does NOT resolve the problem, and moreover the center provided automatically by the Google static map API is always correct: again the center is related to the problem, but it is not the (couse of the) problem.
An aspect that is trivial but important to keep in mind: Google static map draws a path between two locations always by considering the shortest path, i.e. by drawing the shortest straight line.
Therefore if you are in a situation where your path has to go from a location A to a location B, and the shortest path between A and B goes 'around the world' (or better, it goes out from one side of the image), then the path appears 'borken' as in maps that you have shown. In practice A and B are near the left and right margins of the map, and the map can not be centered in some point along the shortest path between A and B because of the others point of the path. And this is what happen when you remove 'Rome': without Rome the map can be centered in a way that the path is not borken.
Formally, I think that the problem appears (i.e. the path is broken), when the projection of the path on the equator is longer than 360 degree of longitudes, and the path always goes in the same direction (i.e. always west to east or always east to west).
Google static map in this situation simply adds another world map next to the first one: if you set the zoom to the minimum, you can see up to three world maps. This is really impractical for several reasons:
you can not zoom out infinitely;
if you want also insert markers into the map they will be drawn only on the 'main' map;
potentially you can have a path that goes around the world (passing in sequence from America, Europe, Asia, and America again and so on...) many times, and it would be really terrible to have so many little maps one after each other;
I googled a lot about this problem, and I didn't find any solution, there is a bug open on the bug tracker, but it is unsolved.
In my opinion the 'right' way to do is simply the following: at most one map and if a path has to goes out from one margin of the map/image, then it should appear on the opposite margin and continues to the destination, drawn on the same map.
So I found a first workaround:
you draw your path, and with the same style (line's color, etc) you also draw the path in a reversed way (Google static map allows to draws multiple paths in the same map), i.e. path=A|B|C&path=C|B|A and this will solve the problem in many situations (i.e. the path exits from one side of the image and enters from the other). Unfortunately this not works always: if you have a path that cross the image margin two consecutive times, then you lose a portion of your path
To solve this problem I found a second workaround:
- not draw simply the path and its reverse, but draw a different path for every pair of locations of the path (and reversed), i.e. for a path A->B->C then: path:A|B,path=B|C,path=C|B,path=B|A and this works always
The drawback is that in this way the URL becomes very long and the limit of 2048 characters for URLs is easily reached.
The best solution would be to compute manually the center, check manually where the path will cross the margin, and only for this portion of the path draw an additional path going between the two locations at the margin (and maybe also the reverse), but I do not think it really worth, although I do not think Google ever will solve this problem.