{"id":13784393,"url":"https://github.com/wdtinc/mapbox-vector-tile-java","last_synced_at":"2025-05-11T19:32:55.805Z","repository":{"id":10597093,"uuid":"62918737","full_name":"wdtinc/mapbox-vector-tile-java","owner":"wdtinc","description":"Java Mapbox Vector Tile Library for Encoding/Decoding ","archived":false,"fork":false,"pushed_at":"2022-10-04T23:32:57.000Z","size":292,"stargazers_count":147,"open_issues_count":16,"forks_count":71,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-08-03T19:08:44.630Z","etag":null,"topics":["java","jts","mapbox-vector-tile"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wdtinc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-08T21:35:28.000Z","updated_at":"2024-07-12T02:44:33.000Z","dependencies_parsed_at":"2022-07-25T02:34:50.789Z","dependency_job_id":null,"html_url":"https://github.com/wdtinc/mapbox-vector-tile-java","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdtinc%2Fmapbox-vector-tile-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdtinc%2Fmapbox-vector-tile-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdtinc%2Fmapbox-vector-tile-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdtinc%2Fmapbox-vector-tile-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wdtinc","download_url":"https://codeload.github.com/wdtinc/mapbox-vector-tile-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225086615,"owners_count":17418764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jts","mapbox-vector-tile"],"created_at":"2024-08-03T19:00:42.050Z","updated_at":"2024-11-17T20:31:54.076Z","avatar_url":"https://github.com/wdtinc.png","language":"Java","readme":"\n# MapBox Vector Tile - Java\n\n[![Build Status](https://travis-ci.org/wdtinc/mapbox-vector-tile-java.svg?branch=master)](https://travis-ci.org/wdtinc/mapbox-vector-tile-java)\n\nContents\n\n- [Overview](#overview)\n    - [Dependency](#dependency)\n    - [Reading MVTs](#reading-mvts)\n    - [Building and Writing MVTs](#building-and-writing-mvts)\n    - [Buffering Polygons Beyond MVT Extent](#buffering-polygons-beyond-mvt-extent)\n- [Examples](#examples)\n- [Generate VectorTile class using .proto](#how-to-generate-vectortile-class-using-vector_tile.proto)\n- [Issues](#issues)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Overview\n\nProvides:\n\n * protoc generated model for Mapbox Vector Tiles v2.1.\n * Provides MVT encoding through use of the Java Topology Suite (JTS).\n * Android API level 15 compatibility (as of version 3.0.0).\n\nSee:\n\n * https://www.mapbox.com/vector-tiles/specification/ for overview of the MVT spec.\n * https://github.com/mapbox/vector-tile-spec/tree/master/2.1 for details on the MVT spec.\n * https://developers.google.com/protocol-buffers/ for details on protoc.\n * https://projects.eclipse.org/projects/locationtech.jts for details on JTS.\n\n### Dependency\n\n#### Maven\n\nLatest version using JTS 15 with android API level 15 support:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.wdtinc\u003c/groupId\u003e\n    \u003cartifactId\u003emapbox-vector-tile\u003c/artifactId\u003e\n    \u003cversion\u003e3.1.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nJTS 14 with no android support:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.wdtinc\u003c/groupId\u003e\n    \u003cartifactId\u003emapbox-vector-tile\u003c/artifactId\u003e\n    \u003cversion\u003e2.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### Gradle\n\nLatest version using JTS 15 with android API level 15 support:\n\n```\ncompile 'com.wdtinc:mapbox-vector-tile:3.1.1'\n```\n\nJTS 14 with no android support:\n\n```\ncompile 'com.wdtinc:mapbox-vector-tile:2.0.0'\n```\n\n### Reading MVTs\n\nPer-tile geometry conversion overview:\n\n![Image of Geometry Conversion Overview](docs/mvt_read_flow.png)\n\nUse MvtReader.loadMvt() to load MVT data from a path or input stream\ninto JTS geometry. The TagKeyValueMapConverter instance will convert\nMVT feature tags to a Map with primitive values. The map will be\nstored as a JTS geometry user data object within the Geometry.\n\nThe JtsMvt object wraps the JTS Geometry with MVT layer information\nand structure.\n\n```java\nGeometryFactory geomFactory = new GeometryFactory();\n\nJtsMvt jtsMvt = MvtReader.loadMvt(\n        Paths.get(\"path/to/your.mvt\"),\n        geomFactory,\n        new TagKeyValueMapConverter());\n\n\n// Allow negative-area exterior rings with classifier\n// (recommended for Mapbox compatibility)\nJtsMvt jtsMvt = MvtReader.loadMvt(\n        Paths.get(\"path/to/your.mvt\"),\n        geomFactory,\n        new TagKeyValueMapConverter(),\n        MvtReader.RING_CLASSIFIER_V1);\n```\n\n### Building and Writing MVTs\n\nPer-layer geometry conversion overview:\n\n![Image of Geometry Conversion Overview](docs/mvt_build_flow.png)\n\n#### 1) Create or Load JTS Geometry\n\nCreate or load any JTS Geometry that will be included in the MVT. The Geometries are assumed\nto be in the global/world units for your target projection. Example: meters for EPSG:3857.\n\n#### 2) Create Tiled JTS Geometry in MVT Coordinates\n\nCreate tiled JTS geometry with JtsAdapter#createTileGeom(). MVTs currently\ndo not support feature collections so any JTS geometry collections will be flattened\nto a single level. A TileGeomResult will contain the world/global intersection\ngeometry from clipping as well as the actual MVT geometry that uses\ntile extent coordinates. The intersection geometry can be used for hierarchical\nprocessing, while the extent geometry is intended to be encoded as the tile geometry.\nKeep in mind that MVTs use local 'screen coordinates' with inverted y-axis compared with cartesian.\n\n```java\nIGeometryFilter acceptAllGeomFilter = geometry -\u003e true;\nEnvelope tileEnvelope = new Envelope(0d, 100d, 0d, 100d); // TODO: Your tile extent here\nMvtLayerParams layerParams = new MvtLayerParams(); // Default extent\n\nTileGeomResult tileGeom = JtsAdapter.createTileGeom(\n        jtsGeom, // Your geometry\n        tileEnvelope,\n        geomFactory,\n        layerParams,\n        acceptAllGeomFilter);\n```\n\nJavaDoc for JtsAdapter.createTileGeom()\n\n```java\n/**\n * Create geometry clipped and then converted to MVT 'extent' coordinates. Result\n * contains both clipped geometry (intersection) and transformed geometry for encoding to MVT.\n *\n * \u003cp\u003eUses the same tile and clipping coordinates. May cause rendering issues on boundaries for polygons\n * or line geometry depending on styling.\u003c/p\u003e\n *\n * @param g original 'source' geometry\n * @param tileEnvelope world coordinate bounds for tile\n * @param geomFactory creates a geometry for the tile envelope\n * @param mvtLayerParams specifies vector tile properties\n * @param filter geometry values that fail filter after transforms are removed\n * @return tile geometry result\n * @see TileGeomResult\n */\npublic static TileGeomResult createTileGeom(Geometry g,\n                                            Envelope tileEnvelope,\n                                            GeometryFactory geomFactory,\n                                            MvtLayerParams mvtLayerParams,\n                                            IGeometryFilter filter)\n```\n\n\n#### 3) Create MVT Builder, Layers, and Features\n\nAfter creating a tile's geometry in step 2, it is ready to be encoded in a MVT protobuf.\n\nNote: Applications can perform step 2 multiple times to place geometry in separate MVT layers.\n\nCreate the VectorTile.Tile.Builder responsible for the MVT protobuf\nbyte array. This is the top-level object for writing the MVT:\n\n```java\nVectorTile.Tile.Builder tileBuilder = VectorTile.Tile.newBuilder();\n```\n\nCreate an empty layer for the MVT using the MvtLayerBuild#newLayerBuilder() utility function:\n\n```java\nVectorTile.Tile.Layer.Builder layerBuilder = MvtLayerBuild.newLayerBuilder(\"myLayerName\", layerParams);\n```\n\nMVT JTS Geometry from step 2 need to be converted to MVT features.\n\nMvtLayerProps is a supporting class for building MVT layer\nkey/value dictionaries. A user data converter will take JTS Geometry\nuser data (preserved during MVT tile geometry conversion) and convert it to MVT tags:\n\n```java\nMvtLayerProps layerProps = new MvtLayerProps();\nIUserDataConverter userDataConverter = new UserDataKeyValueMapConverter();\nList\u003cVectorTile.Tile.Feature\u003e features = JtsAdapter.toFeatures(tileGeom.mvtGeoms, layerProps, userDataConverter);\n```\n\nUse MvtLayerBuild#writeProps() utility function after JtsAdapter#toFeatures() to add the key/value dictionary to the\nMVT layer:\n\n```java\nMvtLayerBuild.writeProps(layerBuilder, layerProps);\n```\n\n#### 4) Write MVT\n\nThis example writes the MVT protobuf byte array to an output file.\n\n```java\nVectorTile.Tile mvt = tileBuilder.build();\ntry {\n    Files.write(path, mvt.toByteArray());\n} catch (IOException e) {\n    logger.error(e.getMessage(), e);\n}\n```\n\n### Buffering Polygons Beyond MVT Extent\n\nFor polygon geometry that will be styled with outlines, it is recommended that\nthe clipping area be larger than the tile extent area. This can be handled like\nthe example in MvtBuildTest#testBufferedPolygon(). Code example:\n\n```java\n// Create input geometry\nfinal GeometryFactory geomFactory = new GeometryFactory();\nfinal Geometry inputGeom = buildPolygon(RANDOM, 200, geomFactory);\n\n// Build tile envelope - 1 quadrant of the world\nfinal double tileWidth = WORLD_SIZE * .5d;\nfinal double tileHeight = WORLD_SIZE * .5d;\nfinal Envelope tileEnvelope = new Envelope(0d, tileWidth, 0d, tileHeight);\n\n// Build clip envelope - (10 * 2)% buffered area of the tile envelope\nfinal Envelope clipEnvelope = new Envelope(tileEnvelope);\nfinal double bufferWidth = tileWidth * .1f;\nfinal double bufferHeight = tileHeight * .1f;\nclipEnvelope.expandBy(bufferWidth, bufferHeight);\n\n// Build buffered MVT tile geometry\nfinal TileGeomResult bufferedTileGeom = JtsAdapter.createTileGeom(\n        JtsAdapter.flatFeatureList(inputGeom),\n        tileEnvelope, clipEnvelope, geomFactory,\n        DEFAULT_MVT_PARAMS, ACCEPT_ALL_FILTER);\n\n// Create MVT layer\nfinal VectorTile.Tile mvt = encodeMvt(DEFAULT_MVT_PARAMS, bufferedTileGeom);\n```\n\n## Examples\n\nSee [tests](https://github.com/wdtinc/mapbox-vector-tile-java/tree/readme_upgrade/src/test/java/com/wdtinc/mapbox_vector_tile).\n\n## How to generate VectorTile class using vector_tile.proto\n\nIf vector_tile.proto is changed in the specification, VectorTile may need to be regenerated.\n\nCommand `protoc` version should be the same version as the POM.xml dependency.\n\nprotoc --java_out=src/main/java src/main/resources/vector_tile.proto\n\n#### Extra .proto config\n\nThese options were added to the .proto file:\n\n * syntax = \"proto2\";\n * option java_package = \"com.wdtinc.mapbox_vector_tile\";\n * option java_outer_classname = \"VectorTile\";\n\n## Issues\n\n#### Reporting\n\nUse the Github issue tracker.\n\n#### Known Issues\n\n * Creating tile geometry with non-simple line strings that self-cross in many places will be 'noded' by JTS during an intersection operation. This results in ugly output.\n * Invalid or non-simple geometry may not work correctly with JTS operations when creating tile geometry.\n\n## Contributing\n\nSee [CONTRIBUTING](CONTRIBUTING.md)\n \n## License\n\nhttp://www.apache.org/licenses/LICENSE-2.0.html\n","funding_links":[],"categories":["Parsers \u0026 Generators","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdtinc%2Fmapbox-vector-tile-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwdtinc%2Fmapbox-vector-tile-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdtinc%2Fmapbox-vector-tile-java/lists"}