You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from __future__ import unicode_literals
from django.contrib.gis.db import models
from postgres_copy import CopyManager
class Timezone(models.Model):
tzid = models.CharField(max_length=80)
# GeoDjango geometry
geom = models.MultiPolygonField(srid=4326)
# CopyManager
objects = CopyManager()
def __str__(self):
representative_string = f"TZID: {self.tzid}"
return representative_string
# Auto-generated `LayerMapping` dictionary for Timezone model
timezone_mapping = {
"tzid": "tzid",
"geom": "MULTIPOLYGON",
}
But I get an error that crashes the terminal. Is this plugin able to work with geometry columns for GeoDjango? Do I need to do something different? The CSV is too big to attach, but you can see the file I am converting from here:
Here is the management command, quoted, and linked.
I have moved it out of the management directory for now because it is not working and I don't want it in with things that are working, but on my local filesystem I have kept it in the proper location.
from django.core.management.base import BaseCommand
from locations.models import *
from utilities import *
from django.conf import settings
# logging
import logging
logger = logging.getLogger("django")
class Command(BaseCommand):
def handle(self, *args, **kwargs):
# Since the CSV headers match the model fields,
# you only need to provide the file's path (or a Python file object)
timezones_csv = settings.TABULAR_DATA_SUBDIRECTORY / "tz.csv"
column_to_field_mapping = {"tzid": "tzid", "geom": "geometry"}
Timezone.objects.all().delete()
insert_count = Timezone.objects.from_csv(
timezones_csv,
mapping=column_to_field_mapping,
)
message = ""
message += f"{insert_count} records inserted"
logger.info(message)
I've tried to capture a stacktrace, but the error seems to take down my terminal. I've exported the contents of a shapefile to CSV using
GeoPandas
:And I try to import on this model:
But I get an error that crashes the terminal. Is this plugin able to work with geometry columns for GeoDjango? Do I need to do something different? The CSV is too big to attach, but you can see the file I am converting from here:
https://github.com/evansiroky/timezone-boundary-builder/releases/download/2024a/timezones-with-oceans-now.shapefile.zip
Thanks!
The text was updated successfully, but these errors were encountered: