{"id":15008927,"url":"https://github.com/realiii/pygeopkg","last_synced_at":"2025-04-09T16:22:46.061Z","repository":{"id":45956366,"uuid":"187678464","full_name":"realiii/pygeopkg","owner":"realiii","description":"A Python library that allows for the creation and population of OGC GeoPackage databases with write access.","archived":false,"fork":false,"pushed_at":"2023-07-04T16:58:07.000Z","size":67,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-22T02:34:46.239Z","etag":null,"topics":["arcgis","geopackage","geopackage-libraries","gis","library","python","python-2","python-3","qgis","spatial","spatial-data"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/realiii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-05-20T16:39:25.000Z","updated_at":"2023-11-11T14:43:22.000Z","dependencies_parsed_at":"2023-12-15T22:00:23.897Z","dependency_job_id":"7bae876f-948c-4d16-b543-c65bb1bd8bf2","html_url":"https://github.com/realiii/pygeopkg","commit_stats":{"total_commits":24,"total_committers":6,"mean_commits":4.0,"dds":"0.33333333333333337","last_synced_commit":"205d00b35632ff8780bbe8bf69704092d99d3fb5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realiii%2Fpygeopkg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realiii%2Fpygeopkg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realiii%2Fpygeopkg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realiii%2Fpygeopkg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/realiii","download_url":"https://codeload.github.com/realiii/pygeopkg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065630,"owners_count":21041932,"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":["arcgis","geopackage","geopackage-libraries","gis","library","python","python-2","python-3","qgis","spatial","spatial-data"],"created_at":"2024-09-24T19:21:45.067Z","updated_at":"2025-04-09T16:22:46.030Z","avatar_url":"https://github.com/realiii.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pygeopkg\n\n*Refer to [fudgeo](https://pypi.org/project/fudgeo/) for modernized GeoPackage\ncapabilities, this package not actively maintained*\n\n**pygeopkg** is a Python compatible library that allows for the creation and\npopulation of (*write-to*) an OGC GeoPackage database, including creating \nfeatures within this resource. \n\n\n## Installation\n\n**pygeopkg** is available from the [Python Package Index](https://pypi.org/project/pygeopkg/).\n\n\n### Python Compatibility\n\nThe **pygeopkg** library is compatible with Python 2+ and Python 3+.\n\n\n## Usage\n\n**pygeopkg** can be used to: \n* Create a new empty GeoPackage from scratch.\n* Create new Feature Classes within a GeoPackage.\n* Populate Feature Classes with geometry and attributes. \n\n\n### Create An Empty GeoPackage\n\n```python\nfrom pygeopkg.core.geopkg import GeoPackage\n\n# Creates an empty geopackage\ngpkg = GeoPackage.create(r'c:\\temp\\test.gpkg')\n```\n\nGeoPackages are created with *three* default Spatial References defined\nautomatically, a pair of Spatial References to handle undefined cases,\nand a WGS 84 entry. \n\nThe definition of the WGS84 entry is flexible - meaning that the \n*WKT for WGS84* can be setup per the users liking. As an example, use with \nEsri's ArcGIS means either using the *EPSG WKT* or the *ESRI WKT*. By\ndefault the *ESRI WKT* is used - However, if *EPSG WKT* is desired, you\nmay provide a ``flavor`` parameter to the create method specifying EPSG.\n\n```\n# Creates an empty geopackage\ngpkg = GeoPackage.create(r'c:\\temp\\test.gpkg', flavor='EPSG')\n```\n\n\n### Create A New Feature Class\n\nTo create a new Feature Class in the empty GeoPackage, you will need\nto tell the GeoPackage the Spatial Reference of the Feature Class\nand the schema (e.g., fields) to be available in the Feature Class.\n\nA Feature Class can be created with *Z* or *M* (or both) enabled. If \neither of these options are enabled, the geometry inserted into the \nFeature Class **must** include a value for the option specified.\n\n```python\nfrom pygeopkg.core.geopkg import GeoPackage\nfrom pygeopkg.core.srs import SRS\nfrom pygeopkg.core.field import Field\nfrom pygeopkg.shared.enumeration import GeometryType, SQLFieldTypes\n\ngpkg = GeoPackage.create(r'c:\\temp\\test.gpkg')\n\nsrs_wkt = (\n    'PROJCS[\"WGS_1984_UTM_Zone_23N\",'\n    'GEOGCS[\"GCS_WGS_1984\",'\n    'DATUM[\"D_WGS_1984\",'\n    'SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],'\n    'PRIMEM[\"Greenwich\",0.0],'\n    'UNIT[\"Degree\",0.0174532925199433]],'\n    'PROJECTION[\"Transverse_Mercator\"],'\n    'PARAMETER[\"False_Easting\",500000.0],'\n    'PARAMETER[\"False_Northing\",0.0],'\n    'PARAMETER[\"Central_Meridian\",-45.0],'\n    'PARAMETER[\"Scale_Factor\",0.9996],'\n    'PARAMETER[\"Latitude_Of_Origin\",0.0],'\n    'UNIT[\"Meter\",1.0]]')\n\nsrs = SRS('WGS_1984_UTM_Zone_23N', 'EPSG', 32623, srs_wkt)\nfields = (\n    Field('int_fld', SQLFieldTypes.integer),\n    Field('text_fld', SQLFieldTypes.text),\n    Field('test_fld_size', SQLFieldTypes.text, 100),\n    Field('test_bool', SQLFieldTypes.boolean))\n\nfc = gpkg.create_feature_class(\n    'test', srs, fields=fields, shape_type=GeometryType.point)\n```\n\n\n#### About Spatial References For GeoPackages\n\nSpatial References in GeoPackages are somewhat loosely defined. You\nmay provide a Spatial Reference of any definition and from any\nauthority - be that EPSG, ESRI, or another source. This library follows\nthis lead and has no restriction on the definitions provided. However,\nit should be noted that if you would like Feature Classes to\nbe readable by major software packages, you should provide a\ndefinition which the software can read appropriately. For example, our testing\nhas found that ArcMap prefers definitions corresponding to its\nown WKT format.\n\nA very simple Spatial Reference object is provided with this package\nfor convenience. It requires the name, authority, Spatial Reference ID,\nand Spatial Reference well known text. This object should be used when\ncreating a Feature Class.\n\n\n### Insert Records Into A Feature Class\n\nRecords can be inserted into a Feature Class using the ``insert_rows`` \nmethod. This method inserts all the rows with a single sql call to \nget the best performance.\n\nGeometry fields on **gpkg** Feature Classes created by this code base will\nalways be named ``SHAPE``. Geometry inserted into this field must always\nbe *WKB*. To create *WKB*, use the utility functions from the conversion \nsubpackage. Currently utility functions exists to handle points, lines\nand polygons (including *Z* and *M* varieties).\n\nThis example shows the creation of a random point Feature Class and\nbuilds upon the code from previous examples. Note that the create Feature Class\nportion of the code is omitted...\n\n```python\nfrom random import choice, randint\nfrom string import ascii_uppercase, digits\nfrom pygeopkg.conversion.to_geopkg_geom import (\n    point_to_gpkg_point, make_gpkg_geom_header)\nfrom pygeopkg.shared.constants import SHAPE\nfrom pygeopkg.core.geopkg import GeoPackage\n\n# NOTE: Builds from previous examples \n# and assumes existing GeoPackage and feature class!\n\ngpkg = GeoPackage(r'c:\\temp\\test.gpkg')\nfc = gpkg.get_feature_class('test')\n\n# Field objects can also be used\nfield_names = [SHAPE, 'int_fld', 'text_fld']\n\n# Generate the geometry header once because it is always the same\npoint_geom_hdr = make_gpkg_geom_header(fc.srs.srs_id)\n\n# Generate some random points and attributes\nrows = []\nfor i in range(10000):\n    rand_str = ''.join(choice(ascii_uppercase + digits) for _ in range(10))\n    rand_int = randint(0, 1000)\n    rand_x = randint(300000, 600000)\n    rand_y = randint(1, 100000)\n    wkb = point_to_gpkg_point(point_geom_hdr, rand_x, rand_y)\n    rows.append((wkb, rand_int, rand_str))\n\nfc.insert_rows(field_names, rows)\n```\n\n\n### Creating OGC Geometry Well Known Binaries\n\nAs mentioned, this library supports the creation of point, line, and \npolygon well known binaries. Functions supporting these capabilities \ncan be found in ``pygeopkg.conversion.to_geopkg_geom``. \n\nExamples are provided below and further examples can be found in the \ntests. See code documentation for more details as warranted.\n\nIt is important to note that *Z* and *M* capabilities are defined at the\ntime a Feature Class is created. If a Feature Class is *Z* or *M* enabled,\nthen a value must be provided for that value. Be sure to pick the \ncorrect conversion function depending on the *Z* and *M* combination \ndesired.\n\n\n#### Point Example\n\nA binary header with srs details is always needed but (in **pygeopkg**) \nis the same for all features in a Feature Class. For best performance,\ncreate this once. \n\n```python\n# Point in WGS 84\nx, y = -119, 34\nhdr = make_gpkg_geom_header(4326)\ngpkg_wkb = point_to_gpkg_point(hdr, x, y)\n```\n\n\n#### Line Example\n\nThe utility function for creating lines expects a list of points \nrepresenting its vertices.\n\n```python\n# Line with ZM Values for use with UTM Zone 23N (WGS 84)\nline = [(300000, 1, 10, 0), (300000, 4000000, 20, 1000),\n        (700000, 4000000, 30, 2000), (700000, 1, 40, 3000)]\nhdr = make_gpkg_geom_header(32623)\ngpkg_wkb = points_zm_to_gpkg_line_string_zm(hdr, line)\n```\n\n\n#### Polygon Example\n\nThe utility function for creating regular polygons expects a list of \nrings where a ring is simply the list of points it contains.\n\n```python\nrings = [[(300000, 1), (300000, 4000000), (700000, 4000000),\n          (700000, 1), (300000, 1)]]\nhdr = make_gpkg_geom_header(32623)\ngpkg_wkb = point_lists_to_gpkg_polygon(hdr, rings)\n```\n\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealiii%2Fpygeopkg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealiii%2Fpygeopkg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealiii%2Fpygeopkg/lists"}