Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable geojson file output from TilePyramid, maybe add to CLI #50

Open
Scartography opened this issue Oct 13, 2022 · 0 comments
Open

enable geojson file output from TilePyramid, maybe add to CLI #50

Scartography opened this issue Oct 13, 2022 · 0 comments

Comments

@Scartography
Copy link
Collaborator

E.G.:

import geojson
from tilematrix import GridDefinition, TilePyramid

mollweide_bounds = (-18041000.0, -9000000.0, 18041000.0, 9000000.0)

# import math
# print(math.gcd(int(mollweide_bounds[2]), int(mollweide_bounds[3])))

mollweide_10m_grid = GridDefinition(
    grid="custom", shape=(9000, 18041), is_global=True,
    bounds=mollweide_bounds,
    srs={'wkt': 'PROJCS["World_Mollweide",GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Mollweide"],PARAMETER["False_Easting",0],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",0],UNIT["Meter",1],AUTHORITY["EPSG","54009"]]'}
    )

# print(mollweide_10m_grid)

mollweide_10m_tmx = TilePyramid(grid=mollweide_10m_grid, tile_size=200, metatiling=16)

print(mollweide_10m_tmx)

print(f"pixel_x_size: {mollweide_10m_tmx.pixel_x_size(zoom=0)}")
print(f"pixel_y_size: {mollweide_10m_tmx.pixel_y_size(zoom=0)}")


mollweide_100m_tmx = TilePyramid(grid=mollweide_10m_grid, tile_size=20, metatiling=16)

print(mollweide_100m_tmx)


print(f"pixel_x_size: {mollweide_100m_tmx.pixel_x_size(zoom=0)}")
print(f"pixel_y_size: {mollweide_100m_tmx.pixel_y_size(zoom=0)}")


mollweide_1000m_tmx = TilePyramid(grid=mollweide_10m_grid, tile_size=2, metatiling=16)

print(mollweide_1000m_tmx)


print(f"pixel_x_size: {mollweide_1000m_tmx.pixel_x_size(zoom=0)}")
print(f"pixel_y_size: {mollweide_1000m_tmx.pixel_y_size(zoom=0)}")



with open("/mnt/data/mollweide100m.geojson", "w") as f:
    f.write("{\n" '"type": "FeatureCollection",')
    f.write("\n" '"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:ESRI::54009" } },')
    f.write("\n" '"features": [')
    for tile in mollweide_100m_tmx.tiles_from_bounds(zoom=0, bounds=mollweide_bounds):
        gj = "    %s,\n" % geojson.Feature(
            geometry=tile.bbox(),
            properties=dict(zoom=tile.zoom, row=tile.row, col=tile.col),
        )
        f.write(gj)
    f.write("]\n" "}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant