Erste Schritte mit casaGeoTools

Einführung

Die casaGeoTools-Bibliothek wurde entwickelt, um leistungsstarke Standortdienste direkt in Ihren Python-Data-Science-Workflow zu integrieren. Diese Anleitung führt Sie durch die Installation, die sichere Authentifizierung und Ihre erste Isochronenabfrage.

1. Installation

Installieren Sie die Bibliothek direkt über PyPI. Nutzen Sie dazu Ihr Terminal oder die Eingabeaufforderung:

pip install casaGeoTools

Für Ihr erstes Skript sollten Sie folgende Pakete importieren:

 

Python Skript

import os
from dotenv import load_dotenv


import pandas as pd
import shapely


# casaGeoTools
from casageo import coder as cc # Wird in diesem Beispiel nicht benötigt
from casageo import spatial as cs
from casageo import tools as ct


pd.set_option("display.max_rows", None)
pd.set_option("display.max_columns", None)
pd.set_option("display.width", 999)

1.1 Erläuterungen

Die pd.set_option() setzen wir, wenn wir alle Spalte im Ergebnisse anzeigen möchten.

2. Zugang und API-Key

Für die Nutzung der Dienste benötigen Sie einen gültigen Zugangsschlüssel.

3. Sicheres Setup (.env)

In professionellen Projekten sollten API-Keys niemals direkt im Code stehen. Wir empfehlen die Nutzung einer .env-Datei.

  1. Erstellen Sie eine Datei namens .env in Ihrem Projektordner
  2. Fügen Sie Ihren Key hinzu: CASAGEOTOOLS_API_KEY=ihr_schluessel_hier
  3. Nutzen Sie python-dotenv, um den Key zu laden

 

Python Skript

import os
from dotenv import load_dotenv
load_dotenv() # Lädt die Variable aus der .env-Datei


API_KEY = os.getenv("CASAGEOTOOLS_API_KEY")


if not API_KEY:
   raise ValueError(
      "No CASAGEOTOOLS_API_KEY found in .env file. Please set your casaGeoTools API key.")


cga = ct.CasaGeoClient(API_KEY)
cga.preferred_language = ["de", "en"]
account_info = cga.account_info().json()


account_info # Ausdruck in Jupyter Notebook
print(account_info) # Ausdruck im Python-Skript


 

4. Ihre erste Abfrage

Die Berechnung von Isochronen mit casaGeoTools ist effizient und liefert Daten im GeoDataFrames-Format.

Python Skript

import shapely


point_hh = shapely.Point(10.008223, 53.9580118) # Standort für den das Einzugsgebiet berechnet wird


cgs = cs.CasaGeoSpatial(cga)
cgs.transport_mode = "car"
cgs.routing_mode = "fast"


single_isolines = cgs.isolines(poin_hh, [3,9,15], range_type="time").dataframe(departure_info=False)


single_isolines # Ausgabe in Jupyter Notebook


print(single_isolines) # Ausgabe im PythonScript