Ticket #468 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

Shapefile read support

Reported by: benwreilly@… Owned by: aric
Priority: normal Milestone: networkx-1.4
Component: networkx Version:
Severity: normal Keywords:
Cc:

Description

I've been using networkx to do some basic GIS topology work here and thought I would push back in something that might be useful to someone. I'm honestly pretty new to all this (this is my first open source contribution to anything) so I would greatly appreciate any suggestions.

I'd particularly like ideas on the tests. Previously I used extensive mocking, but I was worried it was becoming too self-referential and unpythonic.

I noticed other readwrite modules just creating tempfiles and destroying them when finished, so I went that route. Only I couldn't use the built-in Python tempfile module because I couldn't get it to play nice as an OGR datasource, so the test creates a real shapefile (which really consist of three files, .shp, .shx, .dbf) and destroys them when finished.

Attachments

nx_shp.py (2.6 KB) - added by benwreilly@… 3 years ago.
shapefile read support
test_shp.py (1.6 KB) - added by benwreilly@… 3 years ago.
shapefile read tests
shpbundle (3.5 KB) - added by benwreilly@… 3 years ago.
change bundle
networkx-shp.patch (5.0 KB) - added by aric 3 years ago.
shprev1.patch (2.3 KB) - added by benwreilly 3 years ago.
some more documentation

Change History

Changed 3 years ago by benwreilly@…

shapefile read support

Changed 3 years ago by benwreilly@…

shapefile read tests

Changed 3 years ago by benwreilly@…

change bundle

comment:1 Changed 3 years ago by aric

  • Status changed from new to needinfo

That looks good and thanks for writing a test!

I am attaching a patch with your additions and a little editing.

I think we can put it in - but first it should have a description of what kind of shp files it reads, which data it uses, and how the graph is constructed from that data. Written for those of us that aren't GIS hackers -;)

Changed 3 years ago by aric

Changed 3 years ago by benwreilly

some more documentation

comment:2 Changed 3 years ago by benwreilly

Thanks! That was a pretty quick response for a Sunday. :)

I might have put it in the wrong place, but I went ahead and added in some more documentation on how the translation happens:

"Generates a networkx DiGraph? from point and line shapefiles.

Point geometries are translated into nodes, lines into edges. Coordinate tuples are used as keys. Attributes are preserved, line geometries are simplified into start and end coordinates. Accepts a single shapefile or directory of many shapefiles."

comment:3 Changed 3 years ago by Aric Hagberg <aric.hagberg@…>

In [2171e2bc7a0912adb5f5d9e59f1511617a698bb6/networkx]:

Add shapefile reader.
Addresses #468

comment:4 Changed 3 years ago by aric

  • Status changed from needinfo to assigned
  • Milestone changed from networkx-future to networkx-1.4

I pushed the code into the master repository. I'll leave this open for review for a little while to collect feedback and to make any small changes in the base functionality.

comment:5 Changed 3 years ago by aric

  • Status changed from assigned to closed
  • Resolution set to fixed

OK - no comments for now. I'll close this an open another ticket for enhancements.

Note: See TracTickets for help on using tickets.