Package: pygw
pygwThis project aims to provide Python classes that allow users to interact with a GeoWave data store using the same workflows that are available in the programmatic Java API.EnvironmentPython >=3,<=3.7A virtualenv withrequirements.txtinstalledA running GeoWave Java GatewayInstallation From SourceClone GeoWave:git clone https://github.com/locationtech/geowave.gitNavigate to python directory:cd geowave/python/src/main/pythonSet up virtualenv:virtualenv -p python3 venvActivate virtualenv:source venv/bin/activateInstall requirements:pip install -r requirements.txtUsageIn order to usepygw, you must have an instance of GeoWave Py4J Java Gateway Server running.  The gateway can be started by using the GeoWave commandgeowave util python rungateway.You can then importpygwclasses into your Python environment.ExampleThe following is an example of howpygwmight be used to write and query some feature data:fromdatetimeimportdatetimefromshapely.geometryimportPointfrompygw.storeimportDataStoreFactoryfrompygw.store.rocksdbimportRocksDBOptionsfrompygw.geotoolsimportSimpleFeatureBuilderfrompygw.geotoolsimportSimpleFeatureTypeBuilderfrompygw.geotoolsimportAttributeDescriptorfrompygw.geotoolsimportFeatureDataAdapterfrompygw.indeximportSpatialIndexBuilderfrompygw.queryimportVectorQueryBuilderfrompygw.queryimportVectorAggregationQueryBuilder# Create a RocksDB data storeoptions=RocksDBOptions()options.set_geowave_namespace("geowave.example")# NOTE: Directory is relative to the JVM working directory.options.set_directory("./datastore")datastore=DataStoreFactory.create_data_store(options)# Create a point feature typepoint_type_builder=SimpleFeatureTypeBuilder()point_type_builder.set_name("TestPointType")point_type_builder.add(AttributeDescriptor.point("the_geom"))point_type_builder.add(AttributeDescriptor.date("date"))point_type=point_type_builder.build_feature_type()# Create a builder for this feature typepoint_feature_builder=SimpleFeatureBuilder(point_type)# Create an adapter for point typepoint_type_adapter=FeatureDataAdapter(point_type)# Create a Spatial Indexindex=SpatialIndexBuilder().create_index()# Registering the point adapter with the spatial index to your datastoredatastore.add_type(point_type_adapter,index)# Creating a writer to ingest datawriter=datastore.create_writer(point_type_adapter.get_type_name())# Write some features to the data storepoint_feature_builder.set_attr("the_geom",Point(1,1))point_feature_builder.set_attr("date",datetime.now())writer.write(point_feature_builder.build("feature1"))point_feature_builder.set_attr("the_geom",Point(5,5))point_feature_builder.set_attr("date",datetime.now())writer.write(point_feature_builder.build("feature2"))point_feature_builder.set_attr("the_geom",Point(-5,-5))point_feature_builder.set_attr("date",datetime.now())writer.write(point_feature_builder.build("feature3"))# Close the writerwriter.close()# Query the data (with no constraints)query=VectorQueryBuilder().build()results=datastore.query(query)forfeatureinresults:print(feature.get_id())print(feature.get_default_geometry())results.close()# Perform a count aggregation on the data (with a CQL constraint)aggregation_query_builder=VectorAggregationQueryBuilder()constraints=aggregation_query_builder.constraints_factory().cql_constraints("BBOX(the_geom, 0.5, 0.5, 5.5, 5.5)")aggregation_query_builder.constraints(constraints)aggregation_query_builder.count(point_type_adapter.get_type_name())count=datastore.aggregate(aggregation_query_builder.build())print(count)Dev Notes:Building a distributable wheelTo build a wheel file forpygw, simply execute the commandpython setup.py bdist_wheel --python-tag=py3under the active virtual environment.  This will create a distributable wheel under thedistdirectory.Building API documentationThis project has been documented using Python docstrings.  These can be used to generate full API documentation in HTML form. To generate the documentation, perform the following steps:Ensure that the GeoWave Py4J Java Gateway Server is running:geowave util python rungatewayGenerate documentation:pdoc --html pygwNote: This command requires that the python virtual environment is active and that thepygwrequirements have been installed.  This will generate API documentation in thehtml/pygwdirectory.Submodule descriptionsIn general each submodule tries to mimic the behavior of the GeoWave Java API.  If there is ever any question about how something should be done with the Python bindings, the answer is most likely the same as how it is done in Java.  The difference being that function names use underscores instead of camel case as is the convention in Java.  For example if the Java version of a class has a functiongetName(), the Python variant would beget_name().The main difference between the two APIs is how the modules are laid out.  The Python bindings use a simplified module structure to avoid bringing in all the unnecessary complexity of the Java packages that the Java variants belong to.configTheconfigmodule includes a singleton object of type GeoWaveConfiguration calledgw_configthat handles all communication between python and the Py4J Java Gateway.  The module includes several shortcut objects to make accessing the gateway more convenient.  These include:java_gatewayPy4J Gateway Objectjava_pkg: Shortcut forjava_gateway.jvm.  Can be used to construct JVM objects likejava_pkg.org.geotools.feature.simple.SimpleFeatureTypeBuilder()geowave_pkg: Similar tojava_pkg, serves as a shortcut forjava_gateway.jvm.org.locationtech.geowave.reflection_util: Direct access to the Py4J reflection utility.These objects can be imported directly usingfrom pygw.config import <object_name>.NOTE: the GeoWaveConfiguration has aninit()method. This is INTENTIONALLY not an__init__method. Initialization is attempted when the configuration is imported.baseThebasemodule includes common classes that are used by other modules.  This includes the baseGeoWaveObjectclass that serves as a python wrapper for a java reference.  It also includes atype_conversionssubmodule that can be used to convert Python types to Java types that are commonly used in GeoWave.geotoolsThegeotoolsmodule contains classes that wrap the functionality of geotools SimpleFeatures and SimpleFeatureTypes.  These classes can be used to create feature types, features, and data adapters based on simple features.indexTheindexmodule contains classes that are used in creating spatial and spatial/temporal indices.queryThequerymodule contains classes that are used in constructing queries and their constraints.storeThestoremodule contains classes that can be used to establish connections to the various GeoWave backends.  Each store type has a submodule which contains a class that can be used to connect to that store type.  For examplefrom pygw.store.accumulo import AccumuloOptions.  TheDataStoreobject can be constructed by passing the options object to theDataStoreFactory.create_data_store(<options>)method.debug.pyThis exposes a function calledprint_objthat can be used to help with debugging raw java objects. It will print information about the object in question on both the Python side and on the Java server side. There's averboseflag that will give you more information about the object in question.Notes:j_-prefixed notation : Java reference variables are prefixed withj_in order to distinguish them from Python variables