Skip to content

Instantly share code, notes, and snippets.

@edouard-lopez
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edouard-lopez/5223435b5d5a04d7d6e0 to your computer and use it in GitHub Desktop.
Save edouard-lopez/5223435b5d5a04d7d6e0 to your computer and use it in GitHub Desktop.
PAV dataviz
'use strict';
// Your source tile layer extent, expressed in local projection
var bbox = [700000, 6325197, 1060000, 6617738];
// Maximum resolution in meters per pixel (largest area side / tile size).
var maxResolution = 1406.25;
// Scale for each level
var scale = function(zoom) {
return 1 / (maxResolution / Math.pow(2, zoom));
};
// Coordinate to grid transformation matrix
var transformation = new L.Transformation(1, -bbox[0], -1, bbox[3]);
// Official Spatial Reference from http://www.spatialreference.org/ref/epsg/2154/
var crs = L.CRS.proj4js('EPSG:2154',
'+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs',
transformation);
crs.scale = scale; // required by Leaflet 0.4
var map = L.map('map', {
crs: crs,
scale: scale,
center: new L.LatLng(44.8442, -0.5933), // Universal Lat/Lng
zoom: 1,
minZoom: 0,
maxZoom: 18,
attribution: '© <a href="http://metadata.lacub.fr/geosource/apps/search/?uuid=1f8a4be0-900e-4eab-9dcf-55cd9f0a1aed">La CUB</a>'
});
// // Location of tiles (see next paragraph)
new L.tileLayer(
// 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png',
'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
{
id: 'edouard-lopez.ik52o4kd',
continuousWorld: true, // very important
}
).addTo(map);
d3.json('scripts/emplacements-pav.geo.json', function (geojson) {
var geojson = {
"type": "Feature",
"properties": {
"name": "Coors Field",
"amenity": "Baseball Stadium",
"popupContent": "This is where the Rockies play!"
},
"geometry": {
"type": "Point",
"coordinates": [-0.5933, 44.8442],
}
};
console.log(geojson);
L.Proj.geoJson(geojson).addTo(map);
// L.geoJson(geojson).addTo(map);
});
Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "GID": 45.000000, "IDENT": "BB23", "IDENT_X": 1419744.320000, "IDENT_Y": 4189211.390000, "IDENT_O": 0.000000, "TYPEA": null, "GEOM_O": 0.000000, "CDATE": "20001025114100", "MDATE": "20100519124340" }, "geometry": { "type": "Point", "coordinates": [ 419836.84, 6422798.03, 0.0 ] } },
{ "type": "Feature", "properties": { "GID": 46.000000, "IDENT": "BB10", "IDENT_X": 1418954.830000, "IDENT_Y": 4189077.230000, "IDENT_O": 0.000000, "TYPEA": null, "GEOM_O": 0.000000, "CDATE": "20001025114300", "MDATE": "20020624094800" }, "geometry": { "type": "Point", "coordinates": [ 419048.27, 6422670.14, 0.0 ] } },
{ "type": "Feature", "properties": { "GID": 48.000000, "IDENT": "BB24", "IDENT_X": 1419707.740000, "IDENT_Y": 4188257.340000, "IDENT_O": 0.000000, "TYPEA": null, "GEOM_O": 0.000000, "CDATE": "20001025114900", "MDATE": "20100519125352" }, "geometry": { "type": "Point", "coordinates": [ 419819.31, 6421844.48, 0.0 ] } },
{ "type": "Feature", "properties": { "GID": 49.000000, "IDENT": "BB08", "IDENT_X": 1420363.830000, "IDENT_Y": 4187140.560000, "IDENT_O": 0.000000, "TYPEA": null, "GEOM_O": 0.000000, "CDATE": "20001025115000", "MDATE": "20001025115500" }, "geometry": { "type": "Point", "coordinates": [ 420454.43, 6420732.73, 0.0 ] } },
{ "type": "Feature", "properties": { "GID": 50.000000, "IDENT": "BX151", "IDENT_X": 1417433.710000, "IDENT_Y": 4189028.050000, "IDENT_O": 0.000000, "TYPEA": null, "GEOM_O": 0.000000, "CDATE": "20001025115500", "MDATE": "20100519134636" }, "geometry": { "type": "Point", "coordinates": [ 417546.12, 6422614.49, 0.0 ] } },
{ "type": "Feature", "properties": { "GID": 51.000000, "IDENT": "BX81", "IDENT_X": 1417110.770000, "IDENT_Y": 4189173.400000, "IDENT_O": 0.000000, "TYPEA": null, "GEOM_O": 0.000000, "CDATE": "20001027095400", "MDATE": "20001027102800" }, "geometry": { "type": "Point", "coordinates": [ 417205.15, 6422768.4, 0.0 ] } },
{ "type": "Feature", "properties": { "GID": 52.000000, "IDENT": "BX83", "IDENT_X": 1416695.880000, "IDENT_Y": 4189598.260000, "IDENT_O": 0.000000, "TYPEA": "ENTERRE", "GEOM_O": 0.000000, "CDATE": "20001027102800", "MDATE": "20100525104332" }, "geometry": { "type": "Point", "coordinates": [ 416802.66, 6423189.35, 0.0 ] } }
}
@edouard-lopez
Copy link
Author

I ended preprocessing the data to convert them to WSG84 projection:

ogr2ogr -f GeoJSON \
    -t_srs EPSG:4326 \
    -lco COORDINATE_PRECISION=2 \
    -select "GID, IDENT, MDATE"  \
output.geo.json input.shp

I recommend too read this –french– article: Convertir un shapefile en GeoJSON pour Leaflet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment