django-import-export / django-import-export

Django application and library for importing and exporting data with admin integration.
https://django-import-export.readthedocs.org/en/latest/
BSD 2-Clause "Simplified" License
3.01k stars 797 forks source link

About geo formats (shape, geojson) #205

Closed manelclos closed 5 years ago

manelclos commented 9 years ago

Hi,

would you like to see geo formats in django-import-export? I'll code some of these as I need to export geodjango datasets.

GeoJSON: easy, some support in Django itself and more coming in Django 1.8 Shape: generate the shape files, zip them, return the file contents

As there is no support in tablib for these formats, and I will probably use django to implement them, I understand I only need to subclass Format and implement the export_data method, right?

class Format(object):
    ...
    def export_data(self, dataset):
        """
        Returns format representation for given dataset.
        """
        raise NotImplementedError()
bmihelac commented 9 years ago

@manelclos thanks for this idea. It would be ideal to package geo formats as separate app, I would be glad to link to it from the documentation.

jamescw commented 9 years ago

Hi @manelclos I have been doing exactly this but not that happy with my current implementation:

https://gist.github.com/1a15baf57528c8ab4ef9

If you have an alternative method, i would find it very useful!

James

manelclos commented 9 years ago

Hi @jamescw

What are the problems with your current implementation?

In the meantime I tried importing geometries in WKT from an excel file and it works perfectly!

jcsimonin commented 9 years ago

hey @manelclos

I'm trying to import geometries in WKT from a csv file but I get an 'InvalidDimensions error' since WKT contains commas and tablib takes comma as column separator. How did you perform your import? Thanks

manelclos commented 9 years ago

Hi @jcsimonin!

I did the import from a xls file, with a custom Format. I think you'll be good if you quote your field content, as in:

1,foo,"POINT(1 0)"

Would be nice to know if it works for you.

jcsimonin commented 9 years ago

hi @manelclos Thanks for your quick answer but i tried it already and tablib.Dataset() doesn't seem to care..

For now, I changed the tablib/format/csv.py and add the parameter delimiter

_csv = csv.writer(stream, delimiter=';')

It works find but i am not quite satisfied with it.

manelclos commented 9 years ago

Hi @jcsimonin,

I think my example should work in tablib, will check. About the semicolon issue, I'm also affected. I subclassed Format and used Python's csv module. It would be good to have this in import-export, either as configuration or as a "CustomCSV" format. But that should be discussed in it own issue. CC me if you open or find a one related to the problem ;)

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.