Json file does not load on a folium map - geolocation

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)

Related

Geojson map with highcharts

I have a map in geo json file, which I need to use for the highchart. How can I use the geojson map which I created in the highcharts instead of using given maps in highcharts.**
You need to use the Highcharts.geojson method to restructure a GeoJSON object in preparation to be read directly by the series.mapData option.
const states = Highcharts.geojson(geojson, 'map'),
rivers = Highcharts.geojson(geojson, 'mapline'),
cities = Highcharts.geojson(geojson, 'mappoint');
Live demo: https://jsfiddle.net/BlackLabel/gqebvL2t/
API Reference: https://api.highcharts.com/class-reference/Highcharts#.geojson

Reading the file lines as locs in Rascal

In the file IO module there is a function that reads the lines from the file.
list[str] fileLines = readFileLines(fileLoc);
The function neatly returns the strings. Each of these strings are also denotable as a loc with the fileLoc(O, L, <BL, BC> , <EL,EC>) format. How can I load the lines from the file as loc resources?
Short answer: The library function readFiles takes a source location as argument and reads the contents of the file. If that source location contains position information then it will only read the part of the file corresponding to that position information.
Somewhat longer answer:
Here is an illustration:
module Example
void main() {
str text = "a\nbc\ndef\n";
loc tmpLoc = |home:///tmp.txt|;
writeFile(tmpLoc, text); // write example text to file
// Read lines back and print them
println("Using readFileLines:");
for(s <- readFileLines(tmpLoc)) println(s);
// Add position information to tmpLoc that corresponds to each of the lines,
// read it back and print it:
println("Using source location with position info:");
println(readFile(tmpLoc[offset=0][length=1]));
println(readFile(tmpLoc[offset=2][length=2]));
println(readFile(tmpLoc[offset=5][length=3]));
}
the expected output is:
Using readFileLines:
a
bc
def
Using source location with position info:
a
bc
def
Final remarks:
Usually position information is generated automatically
by tools (for example a parser); programmers mostly use that information, they don't have to create it (but they can).
Parsers usually generate full line and column information, here we only use offset and length.

Choropleth Map, Bokeh - Assigning patch colours based on property values

This is my first time trying to build a world map and using GeoJSONDataSource.
I'm trying to assign different colours to the patches, based on the country's 'continent' value in its properties.
Is it possible to do something along the following lines:
p.patches(... fill_color= colours['continent'])
Where colours is a dictionary with continent names as keys, and 'continent' is the country's continent value in the JSON data.
This is my current code:
from bokeh.plotting import figure, output_file, show
from bokeh.io import output_notebook
import numpy as np
from bokeh.models import GeoJSONDataSource
with open('data.geojson') as c:
countries = (c.read())
geo_source = GeoJSONDataSource(geojson=countries)
colours = {'Europe': 'red', 'Oceania': 'purple', 'Asia': 'blue', 'Africa': 'pink', "South America": 'green', "Antarctica": 'yellow', 'North America': 'orange', "Seven seas (open ocean)": 'red'}
p = figure(height=450, width=900, lod_threshold=1)
p.patches(xs='xs', ys='ys', fill_color='blue', source=geo_source)
p.multi_line(xs='xs', ys='ys', line_color='white', line_width=0.1, source=geo_source)
show(p)
EDIT
I have tried approaching this slightly differently by setting the fill_color attribute in patches to an array of colours like so:
a =[colours[c['properties']['continent']] for c in json.loads(countries)['features']]
When running this code in Jupyter Notebook, the following error comes up:
Javascript error adding output! Error: attempted to retrieve property
array for nonexistent field 'fill_color' See your browser Javascript
console for more details.
I did this function in order to asign to a geoJSON the data provided in another JSON.
My geoJSON has the international code for states (ISO 3166-2); my data joins on it.
for state in geo['features']:
codState = str(state['properties']['ISO_3166-2'])
if codState in data.keys():
if data.values() != 0:
state['properties']['data'] = data[codState]
dataJson = json.dumps(geo,ensure_ascii=True)
return dataJson

Log GPS Points to Map

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.

How show two lines on map using gmaps4rails?

I'm developing rails app, which use google maps and paint car routes.
I use gmaps4rails gem for drawling line on a map,
So, I have a plan for car ( array of coordinates for car route by plan ) and report for car ( array of coordinates for car route which was actually drove ).
So, I have to arrays of coordinates - plan and report, example with random points :
#plan = [ [12.124, 12,34253], [11.124, 12,34253], ... [8.124, 5.344] ]
#report = [ [12.224, 12,64253], [10.124, 12,34253], ... [9.124, 6.345] ]
I know how draw one line on map, for example this is view with 'plan' line on map:
%div.container
%div.panel.panel-default.col-sm-9
%div.panel-body.row
#map.col-sm-12
:javascript
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
polyline = #{raw #plan.to_json}
handler.addPolyline(polyline); // and not addPolylines
handler.bounds.extend(polyline[0]);
handler.bounds.extend(polyline[ polyline.length - 1]);
handler.fitMapToBounds();
});
But now I need to draw 'plan' line and 'report' line on the same map.
How can I draw two lines with different colors on the same map?
Thanks kindly.
There is an error in your code, gmaps4rails expects an array of objects providing lat and lng properties. The transformation is quite easy though.
Concerning the options, you can pass them as a second argument. Source code is meant to be very clear.
Anyway, Here is a working plunkr with your data

Resources