palewire / django-postgres-copy

Quickly import and export delimited data with Django support for PostgreSQL's COPY command
https://palewi.re/docs/django-postgres-copy/
MIT License
179 stars 48 forks source link

Support for point fields / multiple csv columns to one field #26

Open ndanielsen opened 8 years ago

ndanielsen commented 8 years ago

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']

palewire commented 8 years ago

Hmm. I never thought to try this. What happens if you preformat the points as WKT format or something that PostGIS expects?

jsfenfen commented 7 years ago

+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.

palewire commented 7 years ago

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?