Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.12.10
python-version: 3.13.7
architecture: x64
- name: Checkout PyTorch
uses: actions/checkout@master
Expand Down
3 changes: 2 additions & 1 deletion django_project/cloud_native_gis/tests/layer_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def test_forms(self):

# Check fields
self.assertEqual(
layer.attribute_names, ['CITY_NAME', 'CITY_TYPE', 'COUNTRY']
layer.attribute_names,
['CITY_NAME', 'CITY_TYPE', 'COUNTRY', 'index']
)
# Check count features
self.assertEqual(
Expand Down
3 changes: 2 additions & 1 deletion django_project/cloud_native_gis/tests/models/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def test_export_layer(self):

self.assertEqual(layer_upload.status, UploadStatus.SUCCESS)
self.assertEqual(
layer.attribute_names, ['CITY_NAME', 'CITY_TYPE', 'COUNTRY']
layer.attribute_names,
['CITY_NAME', 'CITY_TYPE', 'COUNTRY', 'index']
)
# Check count features
self.assertEqual(
Expand Down
21 changes: 19 additions & 2 deletions django_project/cloud_native_gis/utils/geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def collection_to_postgis(filepath, table_name, schema_name) -> dict:
create_schema(schema_name)
delete_table(schema_name, table_name)

gdf = None
if filepath.endswith('.gpkg') or filepath.endswith('.kml'):
layers = list_layers(filepath)
if not layers:
Expand All @@ -40,10 +39,28 @@ def collection_to_postgis(filepath, table_name, schema_name) -> dict:
except IndexError:
pass

if 'index' in gdf.columns:
use_index = False
index_label = None
else:
gdf = gdf.reset_index(drop=True)
gdf.index += 1
use_index = True
index_label = 'index'

# Connect and save
con = 'postgresql://{USER}:{PASSWORD}@{HOST}:{PORT}/{NAME}'.format(
**connection.settings_dict
)
engine = create_engine(con)
gdf.to_postgis(table_name, con=engine, schema=schema_name)

gdf.to_postgis(
table_name,
con=engine,
schema=schema_name,
index=use_index,
index_label=index_label
)

engine.dispose()
return metadata
Loading