1 minute read

The United States Forest Service (USFS) provides Motor Vehicle Use Maps (MVUMs) in GeoPDF (more) format. I would like to put the map rectangles on a MapKit map as an overlay, but the map extents in the PDF were difficult to get to.

I met a helpful resource in the Denver Devs community that pointed me toward the GDAL Python library. Between this library and the MyGeoData website, I was able to get the coordinates into a GeoJSON file in two ways.

Manually: Using MyGeoData Website

This website was great for finding out what I was dealing with, but I was limited to one file at a time, all manually. To get the GeoJSON, just upload the PDF and then select “Dataset Info”. The map extents were output as a rectangle (well, quadrilateral at least)in the following format.

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [-105.72891082981914, 39.7741391086867 ],
            [-105.2340227421917 , 39.7741391086867 ],
            [-105.2340227421917 , 40.07188076474783],
            [-105.72891082981914, 40.07188076474783],
            [-105.72891082981914, 39.7741391086867 ]
          ]
        ]
      }
    }
  ]
}

Scripted: Bash, Python, and GDAL

I had to automate the process and found that I could pull that same metadata from the PDF and save it to JSON in the terminal with

# for a GeoPDF named map.pdf and JSON output map.json
gdalinfo map.pdf -json | tr -d '[:space:]' | grep -o' "wgs84Extent".*\]\]\]\}' > map.json

which outputs (prettified afterward) the following content.

{
  "wgs84Extent": {
    "type": "Polygon",
    "coordinates": [
      [
        [-105.7320528, 40.0698042],
        [-105.7289108, 39.7741391],
        [-105.2330182, 39.7761942],
        [-105.2340227, 40.0718808],
        [-105.7320528, 40.0698042]
      ]
    ]
  }
}

This works perfectly for most of the maps but

References

Other References