fio-l1-vienna-shapefile-recovery
Map (reference ← swipe → agent)
0:00
I'm migrating an old parcel shapefile (`parcels.shp`) into our web viewer, and a reference file `column_map.csv` is provided alongside it. Can you produce a clean GeoJSON `parcels.geojson` with the correct full column names and proper character encoding? The features should come through as Polygon or MultiPolygon.
0:00
System info
{
"adapter": "openrouter",
"model": "google/gemma-4-26b-a4b-it",
"base_url": "https://openrouter.ai/api/v1"
}
0:01
Bash
ls -l
total 56 -rw-r--r-- 1 agent agent 188 Jun 18 10:49 column_map.csv -rw-r--r-- 1 agent agent 6 Jun 18 10:49 parcels.cpg -rw-r--r-- 1 agent agent 25726 Jun 18 10:49 parcels.dbf -rw-r--r-- 1 agent agent 457 Jun 18 10:49 parcels.prj -rw-r--r-- 1 agent agent 8260 Jun 18 10:49 parcels.shp -rw-r--r-- 1 agent agent 580 Jun 18 10:49 parcels.shx
0:05
Read
column_map.csv
1 truncated,original
2 KATASTRALG,KATASTRALGEMEINDE_NAME
3 GRUNDSTUEC,GRUNDSTUECKSNUMMER
4 EIGENTUEME,EIGENTUEMER_NAME
5 WIDMUNG_BE,WIDMUNG_BEZEICHNUNG
6 STRASSE_NA,STRASSE_NAME
7 FLAECHE_M2,FLAECHE_M2
0:40
Write
solve.py
content · 65 lines · py
import geopandas as gpd
import pandas as pd
import json
def main():
# 1. Load the column mapping
# The CSV seems to have some leading/trailing whitespace and a specific format
# Based on the Read output: ' 1\ttruncated,original'
# It looks like it might be tab-separated or have spaces?
# Let's try reading it with pandas and see.
mapping_df = pd.read_csv('column_map.csv', sep=',', skipinitialspace=True)
# Actually, the 'Read' output shows ' 1\ttruncated,original'.
# Let's check the file again or just use a more robust way.
# Re-reading carefully:
# ' 1\ttruncated,original'
# ' 2\tKATASTRALG,KATASTRALGEMEINDE_NAME'
# This looks like a tab separator for the first column, or just weird spacing.
# Let's try reading it with whitespace as separator first to be safe,
# or just read line by line if it's messy.
mapping = {}
with open('column_map.csv', 'r', encoding='utf-8') as f:
lines = f.readlines()
for line in lines[1:]: # Skip header
parts = line.strip().split(',')
if len(parts) == 2:
# parts[0] is ' 2\tKATASTRALG'
# We need to split the first part by whitespace or tab to get the original name
head = parts[0].split()
if len(head) >= 2:
original_name = head[-1] # The last element of the first part
new_name = parts[1].strip()
mapping[original_name] = new_name
print(f"Mapping found: {mapping}")
# 2. Load the shapefile
# Shapefiles often have encoding issues. parcels.cpg might hint at it.
gdf = gpd.read_file('parcels.shp')
print("Shapefile loaded. Columns:", gdf.columns.tolist())
# 3. Rename columns
# We want to rename the 'truncated' names to 'original' (full) names.
# The CSV columns are named 'truncated,original'? No, the header is ' 1\ttruncated,original'
# Let's look at the mapping logic again.
# Line 2: ' 2\tKATASTRALG,KATASTRALGEMEINDE_NAME'
# mapping['KATASTRALG'] = 'KATASTRALGEMEINDE_NAME'
gdf = gdf.rename(columns=mapping)
print("Columns after renaming:", gdf.columns.tolist())
# 4. Ensure geometries are Polygon or MultiPolygon
# GeoPandas handles this mostly, but let's filter or check.
# If there are points or lines, we should ideally only keep Polygons for a parcel viewer.
gdf = gdf[gdf.geometry.type.isin(['Polygon', 'MultiPolygon'])]
# 5. Write to GeoJSON
# Use utf-8 encoding.
gdf.to_file('parcels.geojson', driver='GeoJSON')
print("Successfully wrote parcels.geojson")
if __name__ == "__main__":
main()
Wrote solve.py (2713 chars).
0:42
Bash
python solve.py
Mapping found: {}
Shapefile loaded. Columns: ['KATASTRALG', 'GRUNDSTUEC', 'EIGENTUEME', 'WIDMUNG_BE', 'STRASSE_NA', 'FLAECHE_M2', 'geometry']
Columns after renaming: ['KATASTRALG', 'GRUNDSTUEC', 'EIGENTUEME', 'WIDMUNG_BE', 'STRASSE_NA', 'FLAECHE_M2', 'geometry']
Successfully wrote parcels.geojson
1:05
Edit
solve.py
Edited solve.py.
1:07
Bash
python solve.py
Mapping found: {'KATASTRALG': 'KATASTRALGEMEINDE_NAME', 'GRUNDSTUEC': 'GRUNDSTUECKSNUMMER', 'EIGENTUEME': 'EIGENTUEMER_NAME', 'WIDMUNG_BE': 'WIDMUNG_BEZEICHNUNG', 'STRASSE_NA': 'STRASSE_NAME', 'FLAECHE_M2': 'FLAECHE_M2'}
Shapefile loaded. Columns: ['KATASTRALG', 'GRUNDSTUEC', 'EIGENTUEME', 'WIDMUNG_BE', 'STRASSE_NA', 'FLAECHE_M2', 'geometry']
Columns after renaming: ['KATASTRALGEMEINDE_NAME', 'GRUNDSTUECKSNUMMER', 'EIGENTUEMER_NAME', 'WIDMUNG_BEZEICHNUNG', 'STRASSE_NAME', 'FLAECHE_M2', 'geometry']
Successfully wrote parcels.geojson
1:10
Bash
ls -l parcels.geojson
-rw-r--r-- 1 agent agent 25942 Jun 18 10:50 parcels.geojson
1:11
Bash
head -n 20 parcels.geojson
{
"type": "FeatureCollection",
"name": "parcels",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::31287" } },
"features": [
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Innere Stadt", "GRUNDSTUECKSNUMMER": "0013/1", "EIGENTUEMER_NAME": "Müller GmbH", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Mariahilfer Straße", "FLAECHE_M2": 750.0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625700.0, 483400.0 ], [ 625700.0, 483425.0 ], [ 625730.0, 483425.0 ], [ 625730.0, 483400.0 ], [ 625700.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Mariahilf", "GRUNDSTUECKSNUMMER": "0020/2", "EIGENTUEMER_NAME": "Schönbrunner Bauges. m.b.H.", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Döblinger Hauptstraße", "FLAECHE_M2": 751.25 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625732.0, 483400.0 ], [ 625732.0, 483425.0 ], [ 625762.0, 483425.0 ], [ 625762.0, 483400.0 ], [ 625732.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Währing", "GRUNDSTUECKSNUMMER": "0027/3", "EIGENTUEMER_NAME": "Müller GmbH", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Währinger Gürtel", "FLAECHE_M2": 752.5 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625764.0, 483400.0 ], [ 625764.0, 483425.0 ], [ 625794.0, 483425.0 ], [ 625794.0, 483400.0 ], [ 625764.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Döbling", "GRUNDSTUECKSNUMMER": "0034/4", "EIGENTUEMER_NAME": "Schönbrunner Bauges. m.b.H.", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Höfergasse", "FLAECHE_M2": 753.75 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625796.0, 483400.0 ], [ 625796.0, 483425.0 ], [ 625826.0, 483425.0 ], [ 625826.0, 483400.0 ], [ 625796.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Hütteldorf", "GRUNDSTUECKSNUMMER": "0041/5", "EIGENTUEMER_NAME": "Müller GmbH", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Schönbrunner Allee", "FLAECHE_M2": 755.0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625828.0, 483400.0 ], [ 625828.0, 483425.0 ], [ 625858.0, 483425.0 ], [ 625858.0, 483400.0 ], [ 625828.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Floridsdorf", "GRUNDSTUECKSNUMMER": "0048/6", "EIGENTUEMER_NAME": "Schönbrunner Bauges. m.b.H.", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Bäckerstraße", "FLAECHE_M2": 750.0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625860.0, 483400.0 ], [ 625860.0, 483425.0 ], [ 625890.0, 483425.0 ], [ 625890.0, 483400.0 ], [ 625860.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Brigittenau", "GRUNDSTUECKSNUMMER": "0055/7", "EIGENTUEMER_NAME": "Müller GmbH", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Naschmarkt", "FLAECHE_M2": 751.25 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625892.0, 483400.0 ], [ 625892.0, 483425.0 ], [ 625922.0, 483425.0 ], [ 625922.0, 483400.0 ], [ 625892.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Schönbrunn", "GRUNDSTUECKSNUMMER": "0062/8", "EIGENTUEMER_NAME": "Schönbrunner Bauges. m.b.H.", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Mariahilfer Straße", "FLAECHE_M2": 752.5 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625924.0, 483400.0 ], [ 625924.0, 483425.0 ], [ 625954.0, 483425.0 ], [ 625954.0, 483400.0 ], [ 625924.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Innere Stadt", "GRUNDSTUECKSNUMMER": "0069/9", "EIGENTUEMER_NAME": "Müller GmbH", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Döblinger Hauptstraße", "FLAECHE_M2": 753.75 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625956.0, 483400.0 ], [ 625956.0, 483425.0 ], [ 625986.0, 483425.0 ], [ 625986.0, 483400.0 ], [ 625956.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Mariahilf", "GRUNDSTUECKSNUMMER": "0076/1", "EIGENTUEMER_NAME": "Schönbrunner Bauges. m.b.H.", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Währinger Gürtel", "FLAECHE_M2": 755.0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625988.0, 483400.0 ], [ 625988.0, 483425.0 ], [ 626018.0, 483425.0 ], [ 626018.0, 483400.0 ], [ 625988.0, 483400.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Währing", "GRUNDSTUECKSNUMMER": "0083/2", "EIGENTUEMER_NAME": "Müller GmbH", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Höfergasse", "FLAECHE_M2": 750.0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625700.5, 483427.0 ], [ 625700.5, 483452.0 ], [ 625730.5, 483452.0 ], [ 625730.5, 483427.0 ], [ 625700.5, 483427.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Döbling", "GRUNDSTUECKSNUMMER": "0090/3", "EIGENTUEMER_NAME": "Schönbrunner Bauges. m.b.H.", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Schönbrunner Allee", "FLAECHE_M2": 751.25 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625732.5, 483427.0 ], [ 625732.5, 483452.0 ], [ 625762.5, 483452.0 ], [ 625762.5, 483427.0 ], [ 625732.5, 483427.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Hütteldorf", "GRUNDSTUECKSNUMMER": "0097/4", "EIGENTUEMER_NAME": "Müller GmbH", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Bäckerstraße", "FLAECHE_M2": 752.5 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625764.5, 483427.0 ], [ 625764.5, 483452.0 ], [ 625794.5, 483452.0 ], [ 625794.5, 483427.0 ], [ 625764.5, 483427.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Floridsdorf", "GRUNDSTUECKSNUMMER": "0104/5", "EIGENTUEMER_NAME": "Schönbrunner Bauges. m.b.H.", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Naschmarkt", "FLAECHE_M2": 753.75 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625796.5, 483427.0 ], [ 625796.5, 483452.0 ], [ 625826.5, 483452.0 ], [ 625826.5, 483427.0 ], [ 625796.5, 483427.0 ] ] ] } },
{ "type": "Feature", "properties": { "KATASTRALGEMEINDE_NAME": "Brigittenau", "GRUNDSTUECKSNUMMER": "0111/6", "EIGENTUEMER_NAME": "Müller GmbH", "WIDMUNG_BEZEICHNUNG": "Wohngebiet", "STRASSE_NAME": "Mariahilfer Straße", "FLAECHE_M2": 755.0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 625828.5, 483427.0 ], [ 625828.5, 483452.0 ], [ 625858.5, 483452.0 ], [ 625858.5, 483427.0 ], [ 625828.5, 483427.0 ] ] ] } },
1:30