I am working on creating a map with the demarcation of neighborhoods in the city of São Paulo through the folium.
For that I have a json file with all the neighborhoods in the link below:
https://github.com/DaniloPaula/TCC/blob/master/src/bairros_sp.json
So, I made the code below to get this json file and add it to the map
import json
import folium
bairros_sp = 'bairros_sp.json'
geo_json_data = json.load(open(bairros_sp))
mapa = folium.Map(width=600, height=400, location=[-23.5475, -46.63611], control_scale=True)
mapa
folium.GeoJson(geo_json_data,
style_function=lambda feature: {
'fillColor': 'green',
'color': 'darkred',
'weight': 0.5,
}).add_to(mapa)
mapa
However, I don't have any changes to the map with the addition of the json file.
Can someone help me?
Thank you guys :)
To plot the data on a Folium map, you need to be sure your GeoJson file has the same Geographic coordinate system as Folium (EPSG: 4326). Add this code before folium.Map line.
# check the coordinate system of your GeoJson file
geo_json_data.crs
# and convert it to Folium's coordinate system
geo_json_data = geo_json_data.to_crs(epsg=4326)
I'm trying to use the google places api on the same page as an openlayers map using olgm to serve and embedded google map.
I need to have a handle to the google map in order to construct the places api PlacesService:
var placesService = new google.maps.places.PlacesService(gmap);
However, olgm encapsulates the google map and I can't work out how to get a reference to it:
olgm.OLGoogleMaps = function(options) {
...
var gmap = new google.maps.Map(gmapEl, {
...
Any ideas?
You can access the Google Maps object if you have access to the olgm object:
var olGM = new olgm.OLGoogleMaps({map: map});
var gmap = olGM.getGoogleMapsMap();
For the debug version, if you are using the latest release (0.6 as of today), you can download it here, in the downloads section: https://github.com/mapgears/ol3-google-maps/releases/tag/v0.6
In the .zip you will find a file named ol3gm-debug.js
If you're building your own version, it should appear in the dist directory.
Is it currently possible to use GEOLOCATION to enter points or polygons to a map layer, and access that information in form of SHP file, GPX, or KML?
The only examples I currently see render an IMAGE which is pretty much useless from a 'mapping' standpoint.
Thanks
OpenLayers 3 provides everything you need to write such an application. To track a geolocation, you can do something like this:
var geolocation = new ol.Geolocation({
tracking: true
});
var track;
geolocation.on('change:position', function() {
var coordinate = geolocation.getPosition();
if (track) {
track.appendCoordinate(coordinate);
} else {
track = new ol.geom.LineString(coordinate);
}
});
To create a GPX from the track, you can do
var gpx = new ol.format.GPX().writeFeatures([new ol.Feature(track)]);
The gpx variable now holds a string of the serialized GPX document. You can write its content to a file or upload it to a server or do whatever you want to do with it.
I am trying to work-out the format for Highcharts.
In one of the demos, there is the following call:
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=range.json&callback=?', function(data) {code to build the chart
When the call is made, data similar to the following is returned:
callback([
/* 2009-01-01 */
[1230771600000, -5.8, 0.1],
[1230858000000, -4.1, 1.4],
[1230944400000, -0.5, 4.1],
[1231030800000, -8.9, -0.7],
[1231117200000, -9.7, -3.7],
[1231203600000, -3.4, 3.2],
[1231290000000, -3.9, -0.2],
[1231376400000, -2.4, 6.7],
[1231462800000, 3.8, 6.9],
[1231549200000, 3.1, 6.8]
]);
The problem I am having is that I want to deliver the data through my own AJAX call that will have a result that will contain the graph data as well as some other things. However, I cannot seem to get the format correct so HC can read it. I read their pages about the formats, but with no luck.
I think the problem is the 'callback([]);' container needs to be removed, but when I do that, the data is not displayed in the chart.
lee
i ran into the same problem once. your json has to be parsed before giving it into highcharts series
high charts series accepts an array in this format
[[float,float],[float,float]]
whereas your unparsed json would try to give
[[String,String],[String,String]]
after removing your 'callback([]);' container , you need to parse the individual '[x,y]' points before supplying it to the series object
one way of doing it(in js):
String[] jsonComponents= jsonWithoutContainer.split(",");
Iterate each of the jsonComponents array.
for each jsonComponent - String[] xyComps=jsonComponent.split(",");
x=parseFloat(xyComp[0]); y1=parseFloat(xyComp[1]); y2= parseFloat(xyXomp[2]);
put these in an array, using array1.push(x,y1) and the supply it to the chart.series(array1)
This callback is used for JSONP. You can simply use standard JSON to achieve that:
[[1230771600000, -5.8, 0.1], [1230858000000, -4.1, 1.4], [1230944400000, -0.5, 4.1] ... ]
Without any comments, function etc. If data would look this way, it should work.
Ok, I figured this out.
When jQuery loads all the data, it converts it into a string. Before it can be used by Highcharts, it needs to be converted back to an object using $.parseJSON(data).
Thanks Pawel and Austin for trying to help.
How can I get/set the bonding box of a Google map? I know how to create map using center and zoom, but I need a way to save the view of map based on its boxing and the recreate the same view later using the map bonds (NE and SW of map)
Any idea how I can do this?
I am using MVC 3.
You want to use the map.getBounds() function which returns a LatLngBounds object. From this you can then use getNorthEast() and getSouthWest() to get the coordinates you want.
var bounds = map.getBounds();
var NE = bounds.getNorthEast();
var SW = bounds.getSouthWest();
If you need those LatLng objects to then be strings (for inserting to your DB or writing to a cookie or whatever), just use the toString() function on them.
strNE = NE.toString();
strSW = SW.toString();
So let's assume you write these to a cookie or use Ajax to write these to your DB. Once you get them out of the cookie/DB later, you can then just use those for setting the center of the map:
bounds = new google.maps.LatLngBounds(SW, NE);
map.fitBounds(bounds); // or maybe try panToBounds()
All these functions are documented here: https://developers.google.com/maps/documentation/javascript/reference