I am trying to import a shapefile into a Postgres database using django. When importing problems arise: the data in the cells are shifted, the cell text can break in the middle and partially climb into the next cell. Because of this, numeric fields begin to contain spaces and other string characters. I don’t know the reason for this behavior and ask for help. I will describe my actions step by step.

There is a valid DB table with geometry (point). It is defined in the django gis model and has fields of the types AutoField, CharField, FloatField, and PointField.

I export to shape using the shapefile.py library, the export is successful, the layer opens in ArcMap 10.1, the data looks like it should.

Next, I edit the data in some cell manually in ArcMap — either in the attribute table or move the point. When I press the 'Save Edits' button for an unknown reason (I suspect that this is the cause of import errors), spaces are added to all cells and the cells begin to look like with center alignment. But the data remains in the right cells.

When importing using the same shapefile.py library, an error occurs on the 13th line: Значение '1500 5.01400' должно быть числом с плавающей запятой. This value is in a Double cell, and in the ArcGIS table it is '50 .14 '.

During the import, I output the data of each cell to the console, and starting from the 10th record I see the data offset, as described at the beginning of the topic. By the 13th row, the offset for the first time affects a Double cell, which leads to an error. The data in the cells are all the same, similar. I do not see the reason why they can voluntarily climb into other cells. And I don’t see why gaps are added to the cells when editing attributes in ArcMap.

 Traceback: File "C:\imp_shp\venv\lib\site-packages\django\core\handlers\base.py" in get_response 132. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\imp_shp\import_data\views.py" in to_import 80. for item in shp_deserializer(f, jsonimport): File "C:\imp_shp\import_data\imp_shp.py" in Deserializer 175. for obj in PythonDeserializer(object_list, **options): File "C:\imp_shp\venv\lib\site-packages\django\core\serializers\python.py" in Deserializer 161. data[field.name] = field.to_python(field_value) File "C:\imp_shp\venv\lib\site-packages\django\db\models\fields\__init__.py" in to_python 1817. params={'value': value}, 

    1 answer 1

    Try importing the shape using regular PgAdminIII tools. Postgis

    And about the attributes of the shape - do not believe the data, there are always errors in them - check, edit. perhaps re-exporting data from arcgis will solve some of the problems, in general, study your data. Successes!

    • Thank. Maybe there is an error in the data, but why not on the first line, if the data are of the same type and about the same size? Standard tools import well, but the user will not have access to the database in pgAdmin, so the import should occur through my Django program. Moreover, if you edit the shp-file using another program (I have QGis), then the import is successful. I’m wondering why errors occur when editing with ArcGis. - Mae
    • Often there is a problem because of the integer separator and the fractional part, non-printable characters appear in the attribute table, but here the import usually breaks completely, it's hard to say. In general, if Arcgis has difficulty with a shape, then there is still something wrong in it, yet the native format for it. - gisolog