Skip to content

python encoding tryout #1484

Description

@pvgenuchten

hi i tried the python based encoder today on a CSV file

label,ID,Lat,Lon,pH ,Tot_C,Tot_N,P,K,Ca,Mg,Na,Mn,Cu,Fe,Zn,EC
example1,3,-0.78393,35.08891,5.7,1.84,0.18,10.9,0.44,12.13,2.1,0.45,1.3,0.28,120.4,8.4,
example2,4,-0.77556,35.10607,5.3,1.54,0.15,9.5,0.22,5.21,0.5,0.31,0.8,0.21,187,4.2,
example3,5,-0.79172,35.0989,5.4,1.82,0.18,6.3,0.68,8.06,1.6,0.21,0.8,0.35,133.7,4.7,
example4,6,-0.80082,35.1017,5.5,2.49,0.25,10,0.8,11.92,1.4,0.29,0.8,0.53,258.7,5.5,

using this script:

import csv
from pathlib import Path
import maplibre_tiles

features = []

with open("./points.csv", newline="") as f:
    reader = csv.DictReader(f)
 
    for row in reader:
        print(row)
        features.append({
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    float(row["Lon"]),
                    float(row["Lat"]),
                ],
            },
            "properties": {
                k: v for k, v in row.items() if k not in ("Lat", "Lon")
            },
        })

geojson = {
    "type": "FeatureCollection",
    "features": features,
}

mlt = maplibre_tiles.encode_geojson(
    geojson,
    name="points",
)

Path("points.mlt").write_bytes(mlt)

This throws an error

ValueError: input must be a GeoJSON FeatureCollection: invalid type: floating point `35.08891`, expected i32

From this error i get the impression that the use case is a bit different then expected (i haven't read docs in full detail)

Seems the mlt conversion happens at the tile level using the tiles internal projection? But in that scenario, I'm surpirsed that you use geojson as an input format in the examples, probably conversion between mvt <-> mlt is a more common case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions