Skip to content

Instantly share code, notes, and snippets.

@shortdiv
Created September 21, 2017 18:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shortdiv/b40628838808f37f6c170250f7fa3993 to your computer and use it in GitHub Desktop.
Save shortdiv/b40628838808f37f6c170250f7fa3993 to your computer and use it in GitHub Desktop.

Map Data for Beginners

Data Formats

  • Shapefiles
  • *.shp
  • *.shx
  • *.dbf
  • *.prj
  • *.cpg
  • Geotiff

    • *.tiff
  • GeoJSON (Geographic JSON)

  • TopoJSON (Topographic JSON)

  • KML (Keyhole Markup Language)

Developed for use by Google Earth. Keyhole Markup Language is an XML notation for expressing geographic annotation and visualization within Internet-based, two-dimensional maps and three-dimensional Earth browsers.

  • GPX (GPS Exchange Format)

    GPX is an XML schema designed as a common GPS data format for software applications.

    • *.cpg
  • WKT (Well Known Text)

Well-known text is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems.

Tools

Let's convert some data

shp -> json

❯ brew install gdal

❯ which ogr2ogr

❯ ogr2ogr -f GeoJSON us_states.json cb_2016_us_state_20m.shp

❯ topojson -o us_states_topo.json --id-property GEOID --properties name=NAME us_states.json

shp -> geojson

csv -> geojson

<OGRVRTDataSource>
    <OGRVRTLayer name="source">
        <SrcDataSource>/PATH/TO/source.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
        <GeometryField encoding="PointFromColumns" x="LONGITUDE COLUMN HERE" y="LATITUDE COLUMN HERE"/>
    </OGRVRTLayer>
</OGRVRTDataSource>

❯ ogr2ogr -f GEOJson geo_result.json source.vrt

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