How to generate encoded polylines from shapefile/ kml? - google-maps

I need to convert a shapefile/ kml to encoded polyline format for a certain project. Does anyone know of a simple conversion tool or code that achieves the same ?

You'll first want to convert your KML/SHP to a list of lat/long pairs. For KML, you can simply open the KML file in an editor to get the lat/long pairs. For SHP, you can first use shp2kml to convert to KML.
Then, use the encoding library in the Maps API, or you can write your own encoder using the algorithm.

Your term shapefile/kml is confusing. If you want to convert from an ESRI shapefile to a kml file, the utility ogr2ogr works like this:
ogr2ogr -f "KML" outputfile.kml sourcefile.shp.
For downloads, ogr2ogr is part of the GDAL distribution: http://www.gdal.org/

Related

How to get GDAL/ogr2ogr to output GeoJSON as feature-per-line instead of a formatted FeatureCollection?

I'm trying to convert some Very Big Shapefiles into GeoJSON so that I can run them through tippecanoe and create a .mbtiles to upload to Mapbox Studio for hosting and styling.
I can use ogr2ogr to create my GeoJSON file just fine, however it outputs a FeatureCollection with nice formatting. What I want is a .json file with one feature per line, so that I can use the 'Parallel processing of input' feature of Tippecanoe and speed up creation of my .mbtiles.
Question 1: Is there a way to do this simply with ogr2ogr? I can't seem to find a relevant option in the GDAL GeoJSON driver docs.
Question 2: Alternatively, could ogr2ogr output a GeoJSON text sequence instead of a FeatureCollection file?
If you make an array of the ids or any other attribute in your Shapefile, you could loop through this list and use the ogr2ogr --where option to export features one by one. See also this example https://gis.stackexchange.com/questions/35296/how-to-use-where-sql-in-an-ogr2ogr-loop-in-gdal-ogr-bash#35297
Q1. Well, you can extract the individual features with the help of a UNIX tool - jq.
jq --compact-output ".features" input_featurecollection.geojson > output_features_only.geojson
This will have each record as a separate geojson feature
Q2 you can pipe in your input geojson file to this command and echo the output.
You can use ogr2ogr to output a geojson sequence as you suggested in question 2 #craigsnyders:
ogr2ogr -f GeoJSONSeq -t_srs EPSG:4326 output.json input.shp

How to embed a map into Netlogo using GIS extension?

The format of the map imported should be preferably ".shp" file.Also please tell how to create such a file. I have tried KML but it didn't work.
Yes, vectors need to be .shp to be imported. You can create vector files in most GIS programs (ArcGIS, QGIS, etc) and export to .shp. Or there's online tools for converting KML to .shp (eg http://www.zonums.com/online/kml2shp.php)
Raster files need to be saved as .ASC or .GRD for use as a dataset in Netlogo.

Combining additional data with Shapefile using GeoJSON and Gdal

I used Mike Bostock's great tutorial to make a simple map using downloaded shapefiles and processing them with GDAL into GeoJSON files.
http://bost.ocks.org/mike/map/
I'm trying to build on this learning by taking a county-level shapefile map and marrying it with additional demographic data (CSV) so that I can load a single GeoJSON file and not have to use Javascript to merge the data at runtime. The goal is to have a county-level heatmap.
The CSV file has an ID column that looks like this: 01348. While the Shapefile has two ID columns that are 01 and 348.
Is it possible to use GeoJSON to store this kind of data? If so, what kind of terminal commands must I use to combine the two?
Little trick:
When converting from Shape file to GeoJSON, keep "id-a":"01";"id-b":"348" as neighbors in this order.
use a simple regex to delete all ";"id-b":" and thus obtain "id-a":"01348".
go ahead to inject your CSV property given the common ID, see: How to add properties to topojson file?
That's should work.

how to create a vector map of some locations

I want to mark some locations in a vector map. And would like to save the map in pdf format with separate layers.I tried arcgis but the map is online cannot export it to a file. can i know what is the common and standerd way of representing data using a vecotr map
Try this vector maps first, they have free versions, it can be useful:[http://vectormap.info/free-maps-for-all-designers-and-mappers][1] it could be easier for you too

Best way to overlay an ESRI shapefile on google maps?

What is the best way to overlay a shapefile in Google Maps?
After some reading suggests that, converting shapefile into KML and overlaying KML in Google map is an option. If that is the case, how do I convert a shapefile into KMLs?
I believe there would be a few open source tools available for this conversion. Can anyone point to a tool to covert a shapefile to KML without any loss of data?
I like using (open source and gui friendly) Quantum GIS to convert the shapefile to kml.
Google Maps API supports only a subset of the KML standard. One limitation is file size.
To reduce your file size, you can Quantum GIS's "simplify geometries" function. This "smooths" polygons.
Then you can select your layer and do a "save as kml" on it.
If you need to process a bunch of files, the process can be batched with Quantum GIS's ogr2ogr command from osgeo4w shell.
Finally, I recommend zipping your kml (with your favorite compression program) for reduced file size and saving it as kmz.
as of 12.03.2019 FusionTables is no more...
Import the Shapefile into Google FusionTables ( http://www.google.com/fusiontables ) using http://www.shpescape.com/ and from there you can use the data in a number of ways, eg. display it using GoogleMaps.
I would not use KML. Instead, use GeoJSON which you can natively consume in Google Maps API now. It is a newer feature that didn't exist from the original responses.
In any case, simply open the SHP file in Quantum GIS, and then you can output it in any format you like (KML, GeoJSON).
If you are using Google Maps for Work, I found a premium extension that handles loading shapefiles directly where you can just connect direct to the shapefile that you generate from ESRI. I did a search on the CMaps site and found this snippet which loaded US by state shapefile: https://gmapsplugin.net/cmapsanalytics/assets/shapes/usstates.shp
var cMap = new centigon.locationIntelligence.MapView();
cMap.key([your_api_key]);
cMap.layerNames(["Basic Shapes"]);
cMap.dbfKeys([['Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','West Virginia','Wisconsin','Wyoming']]);
cMap.userShapeKeys([['Massachusetts','Minnesota','Montana','North Dakota','Hawaii','Idaho','Washington','Arizona','California','Colorado','Nevada','New Mexico','Oregon','Utah','Wyoming','Arkansas','Iowa','Kansas','Missouri','Nebraska','Oklahoma','South Dakota','Louisiana','Texas','Connecticut','New Hampshire','Rhode Island','Vermont','Alabama','Florida','Georgia','Mississippi','South Carolina','Illinois','Indiana','Kentucky','North Carolina','Ohio','Tennessee','Virginia','Wisconsin','West Virginia','Delaware','District of Columbia','Maryland','New Jersey','New York','Pennsylvania','Maine','Michigan','Alaska']]);
cMap.labels([['Massachusetts','Minnesota','Montana','North Dakota','Hawaii','Idaho','Washington','Arizona','California','Colorado','Nevada','New Mexico','Oregon','Utah','Wyoming','Arkansas','Iowa','Kansas','Missouri','Nebraska','Oklahoma','South Dakota','Louisiana','Texas','Connecticut','New Hampshire','Rhode Island','Vermont','Alabama','Florida','Georgia','Mississippi','South Carolina','Illinois','Indiana','Kentucky','North Carolina','Ohio','Tennessee','Virginia','Wisconsin','West Virginia','Delaware','District of Columbia','Maryland','New Jersey','New York','Pennsylvania','Maine','Michigan','Alaska']]);
cMap.polyDataSources([centigon.locationIntelligence.CMapAnalytics.DATA_PROVIDERS.SHAPE_DATAPROVIDER]);
cMap.layerTypes([centigon.mapping.Layer.TYPE.POLY]);
cMap.locations([["https://gmapsplugin.net/cmapsanalytics/assets/shapes/usstates.shp"]]);
cMap.panTo("USA");
cMap.zoomLevel(3);
Do you mean shapefile as in an Esri shapefile? Either way, you should be able to perform the conversion using ogr2ogr, which is available in the GDAL packages. You need the .shp file and ideally the corresponding .dbf file (which will provide contextual information).
Also, consider using a tool like MapShaper to reduce the complexity of your shapefiles before transforming them into KML; you'll reduce filesize substantially depending on how much detail you need.
Free "Export to KML" script for ArcGIS 9
Here is a list of available methods that someone found.
Also, it seems to me that the most efficient representation of a polygon layer is by using Google Maps API's polyline encoding, which significantly compresses lat-lng data. But getting into that format takes work: use ArcMap to export Shape as lat/lng coordinates, then convert into polylines using Google Maps API.
Just to update these answers, ESRI has included this tool, known as Layer to KML in ArcMap 10.X. Also, a Map to KML tool exists.
Simply import the desired layer (vector or raster) and choose the output location, resolution, etc. Very simple tool.
2018 already... I've found this fantastic online tool http://mapshaper.org/ to convert from ESRI shapefiles to SVG, TopoJSON, GeoJSON.
Here is the explanation of how to use it https://www.statsilk.com/maps/convert-esri-shapefile-map-geojson-format
Fast and straightforward! :)