rosreestr2coord

repository·master·Indexed 42 days ago

https://github.com/rendrom/rosreestr2coord

A Python tool and library for calculating land plot coordinates based on cadastral numbers using data from the NSPD Geoinformation Portal. Version 5.3.3 supports fetching geometry via the Area class or CLI, with capabilities to export data to GeoJSON, KML, and CSV formats. It includes utilities for batch processing with rate-limiting delays, coordinate transformation to WGS84, and cadastral code sanitization.

Tokens
5K
Snippets
24
Records
26
Agent score
48%

What's inside rosreestr2coord

  1. Install rosreestr2coord for Development

    master

    To set up a development environment with editable installation and virtual environments:

    1. Clone the repository:
      git clone https://github.com/rendrom/rosreestr2coord
      cd rosreestr2coord
    2. Create and activate a virtual environment:
      • Linux/MacOS: . ./env/bin/activate
      • Windows: . ./env/Scripts/activate
    3. Install in editable mode:
      pip install -e .
      pip install -e .[dev]
    
    ```bash
    # Example workflow
    python -m venv ./env
    . ./env/bin/activate
    pip install -e .
  2. Use the Area class in Python

    master

    You can use rosreestr2coord as a library in your Python projects by importing the Area class.

    from rosreestr2coord import Area
    
    # Create an Area object with a cadastral number
    area = Area("38:06:144003:4723")
    
    # Convert data to GeoJSON format
    area.to_geojson()
  3. Reference: Area Type codes (-t)

    master

    When using the -t flag, select the appropriate integer code for the type of area:

    1: Real estate objects (Land plots, Buildings, Structures, etc.)
    2: Cadastral division (Districts, Quarters)
    4: Administrative-territorial division (Municipalities, Settlements)
    5: Zones and territories (Cultural heritage, Protected areas, etc.)
    7: Territorial zones
    15: Object complexes (Unified real estate complexes, etc.)
  4. Perform batch parsing with batch_parser()

    master

    The batch_parser function allows for processing multiple area codes in a single execution. It handles individual area requests, manages delays between requests to avoid rate limiting, and provides retry logic for failed requests.

    Results can be exported to CSV or JSON formats. If a TimeoutException occurs, the process stops and suggests that your IP might be blocked.

    Parameters:

    • codes (list of str): A list of area codes to parse.
    • with_log (bool): Whether to enable logging for each area. Defaults to False.
    • file_name (str): The base name for the output files. Defaults to `
  5. Reference: rosreestr2coord CLI flags

    master

    The following flags are available for the rosreestr2coord command line interface:

    -h - help
    -c - cadastral number
    -p - path for intermediate files
    -o - path for the resulting geojson file
    -t - area type (see below)
    -l - batch load from a text file
    -r - do not use caching
    -P - load via proxy
    -v - show version
    -u - set proxy address (e.g., --proxy_url 'http://user:password@12.345.67.89:9876')
  6. Reference: Area class constructor parameters

    master

    The Area class constructor accepts the following parameters:

    code: Cadastral number of the plot.
    area_type: Type of area.
    media_path: Path for temporary files.
    with_log: Enable action logging.
    coord_out: Coordinate output format (e.g., 'EPSG:4326').
    center_only: If True, only exports center coordinates.
    with_proxy: If True, requests are sent via a proxy server.
    use_cache: If True, uses request caching.
    proxy_url: Proxy server address.
  7. Use rosreestr2coord via CLI

    master

    The rosreestr2coord tool can be run directly from the command line to fetch coordinates for specific cadastral numbers or batches.

    Important: This version uses the new NSPD API (replacing PPK). Area type codes have changed significantly compared to version 4 and below.

    # Get coordinates for a single cadastral number
    rosreestr2coord -c 38:06:144003:4723
    
    # Batch process from a text file (one number per line)
    rosreestr2coord -l ./cadastral_numbers_list.txt
  8. Export a single area to GeoJSON

    master

    Use area_json_output to export a single area object to a GeoJSON file. This method calls the area's internal to_geojson_poly method. The file is saved to the output directory using the area.file_name.

    from rosreestr2coord.export import area_json_output
    
    # Returns the geojson string
    geojson = area_json_output(output="/path/to/output", area=area, with_attrs=True)
  9. Export geometry to GeoJSON or KML

    master

    Once an Area object has successfully retrieved a feature via get_geometry(), you can export that data into standard formats.

    Export to GeoJSON

    Use to_geojson(dumps=True) to get a JSON string, or to_geojson(dumps=False) to get a Python dictionary.

    Export to KML

    Use to_kml() to generate a KML string. This method will raise a NoCoordinatesException if no geometry has been fetched yet.

    from rosreestr2coord.parser import Area
    
    area = Area(code="77:01:0001001:1234", area_type=1)
    area.get_geometry()
    
    # Get GeoJSON dictionary
    geojson_dict = area.to_geojson(dumps=False)
    
    # Get KML string
    kml_string = area.to_kml()
  10. Use the Area class to retrieve coordinates

    master

    The Area class is the primary interface for fetching geographic data from the Rosreestr geoportal based on a specific code and area type. You can initialize an Area object with a cadastral code and then call get_geometry() to retrieve the spatial data.

    Initialization Parameters

    • code (str): The cadastral code to search for.
    • area_type (int, optional): The type of area. See Area Type Mapping. Defaults to 1.
    • coord_out (str): The target coordinate system (e.g., EPSG:4326). Defaults to EPSG:4326.
    • with_proxy (bool): Whether to use a proxy for the request.
    • use_cache (bool): Whether to use caching.
    • timeout (int): Request timeout in seconds.
    from rosreestr2coord.parser import Area
    
    # Initialize for a real estate object
    area = Area(code="77:01:0001001:1234", area_type=1)
    
    # Fetch the geometry
    geometry = area.get_geometry()
    if geometry:
        print(geometry)
  11. Convert cadastral codes to safe filenames with `code_to_filename`

    master

    Use code_to_filename to sanitize a cadastral code string for use as a filename. It replaces colons (:) with underscores (_) and forward slashes (/) with hyphens (-).

    from rosreestr2coord.utils import code_to_filename
    
    filename = code_to_filename("02:12/34")
    print(filename)  # Output: "02_12-34"