django-postgres-copy
django-postgres-copy copied to clipboard
Support for point fields / multiple csv columns to one field
Great project! I love it! Wondering if i can import a csv that contains geographical data.
For example, something like this
c = CopyMapping( MyModel, "./data.csv", dict(point=['x', 'y'], number='NUMBER') ) c.save()
Here's a row from the dataset for example: ['-77.0297110577', '38.9291522717', '11802074', '8330232', 'False', 'P173', 'NO PARKING STREET CLEANING', '3200 BLOCK 13TH ST NW EAST SIDE', 'DC', '4D', '806540', '5618.0', '397424', '140141', 'Parking_Violations_in_April_2010.csv', '2010-04-06T09:39:00.000Z']
Hmm. I never thought to try this. What happens if you preformat the points as WKT format or something that PostGIS expects?
+1 It looks like this, or something pretty close to it, would work--see this SO answer. A few years ago I was doing something comparable by using django.contrib.gis.geos.GEOSGeometry -- for a geosgeometry g, g.hex work(ed), though I can't remember why I went that route.
I'm all for trying it, I just want the API syntax we select to be as clear as possible. Generally this library is modeled on the layout of Django's LayerMapping tool for loading shapefiles. You see anything there we could crib from?