Code Monkey home page Code Monkey logo

Comments (5)

andwoi avatar andwoi commented on June 2, 2024 1

I suspect QGIS is crashing because the file is too large. As @chris mentioned, you can split the geojson files into smaller chunks and work with it that way. Here's a python snippet that will look for individual polygon features and write line-delimited geojson (geojsonl) that QGIS can work with. This doesn't require additional modules over python's standard library. Hope that helps!

import json

# decompressed geojson file. 
with open("Minnesota.geojson") as inf:
    counter = 0
    batch = 0
    # adjust this value to change the number of features per file.
    buildings_per_file = 500_000

    file_template = "Minnesota-{}.geojsonl"
    target_file = open(file_template.format(batch), 'w') 
    line = inf.readline()
    while line:
        # filter to look for polygon features
        if 'Polygon' in line:
            line = line.strip().strip(",")
            parsed_line = json.loads(line)
            geom = parsed_line['geometry']
            target_file.write(f"{json.dumps(geom)}\n")
            counter += 1
        if (counter > 0 ) and ((counter % buildings_per_file) == 0):
            target_file.close()
            print(f"completing batch {batch:,}. total lines extracted: {counter:,}")
            batch += 1
            target_file = open(file_template.format(batch), 'w') 
        line = inf.readline()
    target_file.close()
    print(f"completing batch {batch:,}. total lines converted: {counter:,}")

from usbuildingfootprints.

chris avatar chris commented on June 2, 2024

Since you're using an ArcGIS product, maybe a shapefile will import better? If you have the GDAL command line tools, you could convert the GeoJSON file to a Shapefile with something like:

ogr2ogr -f "ESRI Shapefile" Minnesota.shp Minnesota.geojson

In general, most of these are quite large files, so opening the entire state in QGIS or similar may not be very workable. There are a variety of different ways you can do this, but I'd boil this down to two basic categories:

  1. Load the data into PostGIS and then do queries on it for what you're after. You can also query for the geometries within an area you're studying and then export that back out to GeoJSON.
  2. Write a program that reads in the GeoJSON and filters it similarly to PostGIS mentions above.

I've also seen some GeoJSON "splitting" utilities out there. I haven't used any, so don't know much about them, but they may be a way to simply break the single state file up into say 10 smaller files.

from usbuildingfootprints.

alasdairrae avatar alasdairrae commented on June 2, 2024

If anyone's looking for files that will load into QGIS (or similar software) quickly then I have a set I batch converted to GeoPackage (gpkg) with gdal - here they are: https://automaticknowledge.co.uk/us-building-footprints/

(note that they are not the very latest iteration of the files)

This is what I used to batch convert the files didn't take too long do do the whole set, maybe a few hours, and now I can load single states into QGIS much more quickly

for %f in (*.geojson) do ogr2ogr -f "GPKG" %~nf.gpkg %f

from usbuildingfootprints.

alasdairrae avatar alasdairrae commented on June 2, 2024

For anyone looking for files that load into QGIS (or other GIS software) much faster than the original geojson files, then we have produced an updated set of geopackage files for each state, available here:

https://automaticknowledge.co.uk/resources/#USBuildings

These were converted to gpkg from geojson and we also added in county codes and names so that users can filter by county if they need to.

from usbuildingfootprints.

npr99 avatar npr99 commented on June 2, 2024

Thank you!

from usbuildingfootprints.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.