Minimal exporter that connects to an existing PostgreSQL database, runs one optimized query, and writes per‑district DXF files in R2000 format. Each parcel is drawn as an exterior LWPOLYLINE and labeled at its centroid with "Mahalle-Parsel-Ada".
src/— application code (src/app.py)scripts/— runnable scripts (scripts/command.shfor cron)config/— container configsconfig/cron.d/dxf_export— cron job definition (daily 01:00)config/supervisor/supervisord.conf— keeps cron in foreground
output/— generated DXF files (<ILCE>.dxf)Dockerfile— container image for the exporterdocker-compose.yml— single service to run the exporter (dxf).env/.env.example— database connection configurationrequirements.txt— Python dependencies
Python3.13 (or recent 3.x)psycopg2-binary,loguru,python-dotenv,ezdxf,shapely- Existing PostgreSQL database accessible from the runtime environment
- Set the environment variables in
.env:DB_HOST,DB_PORT,DB_USER,DB_PASSWORD,DB_NAME
- The app loads
.envviapython-dotenvand uses only the optimized SQL (SQL_QUERY_OPTIMIZED). - If PostgreSQL runs on your Windows host, use
DB_HOST=host.docker.internalso the container can connect to it. - No database container is started; ensure network/firewall allows the container to reach your existing DB.
- Local
pip install -r requirements.txtpython src/app.py
- Docker
docker-compose up --build- The container runs
supervisordwhich startscronin foreground to keep the container alive. - One‑off job run inside container:
docker-compose exec dxf bash -lc "/app/scripts/command.sh" - Optional: add a restart policy in
docker-compose.yml(restart: always) if you want the service to auto‑start on daemon reboot.
- Schedule: daily at
01:00. - Definition file:
config/cron.d/dxf_export - Command:
0 1 * * * root /app/scripts/command.sh >> /var/log/dxf_cron.log 2>&1 - Logs:
- App logs go to container stdout via
Loguru. - Cron job output is appended to
/var/log/dxf_cron.loginside the container.
- App logs go to container stdout via
- Change schedule: edit
config/cron.d/dxf_exportand rebuild (docker-compose up --build). - Timezone: cron uses the container's timezone. If you need local time (not UTC), set
TZvia environment and installtzdatain the image. Example compose env:TZ=Europe/Istanbul. Example Dockerfile addition:apt-get update && apt-get install -y tzdata. - Verify cron running:
docker-compose exec dxf bash -lc "ps aux | grep -E 'cron|supervisord'" - Check latest cron output:
docker-compose exec dxf bash -lc "tail -n 200 /var/log/dxf_cron.log"
- Location:
outputs/ - Files: one DXF per district (e.g.,
OSMANGAZİ.dxf). - Format:
R2000, layersPARCELS(polylines) andLABELS(text). - Label: centroid text
"<Mahalle>-<Parsel>-<Ada>". - Persistence: In Docker,
./outputsis mounted into the container (./outputs:/app/outputs) so files survive container restarts.
- Uses only
SQL_QUERY_OPTIMIZED; no CRS transformations. - Accepts
PolygonandMultiPolygongeometries viaORJINAL_WKT. - Non‑polygon geometries or invalid WKT are skipped with warning logs.
- Customization: layer names, text height, or line thickness can be adjusted in
src/app.py. - Performance: the exporter streams rows and avoids holding full datasets in memory; keep
outputs/on a fast disk for best results.
- Connectivity: verify
.envvalues and that the container/host can reach the DB (DB_HOST,DB_PORT). - Permissions: ensure the
outputs/directory is writable (mounted in compose). - Logs: check
docker logsfor app output and/var/log/dxf_cron.logfor cron job messages. - Windows paths: if you change volume mappings, prefer relative paths (
./outputs) to avoid drive letter quirks.