def literal(self, value): """ Constructs an expression with the given literal value. Args: value (any): The literal value to use. Returns: An Expression with the given literal value. """ if isinstance(value, datetime): # Convert the date to a string value = value.strftime("%Y-%m-%dT%H:%M:%S") if isinstance(value, str): # Prevent Py4J from assuming the string matches up with the char variant method filter_factory_class = self._java_ref.getClass() object_class = reflection_util.classForName("java.lang.Object") class_array = java_gateway.new_array(java_pkg.java.lang.Class, 1) class_array[0] = object_class method = filter_factory_class.getMethod("literal", class_array) objects_array = java_gateway.new_array(java_pkg.java.lang.Object, 1) objects_array[0] = value return method.invoke(self._java_ref, objects_array) if isinstance(value, BaseGeometry): return self._java_ref.literal(GeometryType().to_java(value)) return self._java_ref.literal(value)
def _invoke_filter_method_by_name(j_filter_factory, name, filter): filter_factory_class = j_filter_factory.getClass() filter_class = reflection_util.classForName("org.opengis.filter.Filter") class_array = java_gateway.new_array(java_pkg.java.lang.Class, 1) class_array[0] = filter_class method = filter_factory_class.getMethod(name, class_array) objects_array = java_gateway.new_array(java_pkg.java.lang.Object, 1) objects_array[0] = filter return method.invoke(j_filter_factory, objects_array)
def _invoke_filter_list_method_by_name(j_filter_factory, name, filters): filter_factory_class = j_filter_factory.getClass() list_class = reflection_util.classForName("java.util.List") class_array = java_gateway.new_array(java_pkg.java.lang.Class, 1) class_array[0] = list_class method = filter_factory_class.getMethod(name, class_array) filter_list = java_pkg.java.util.ArrayList() for filter in filters: filter_list.append(filter) objects_array = java_gateway.new_array(java_pkg.java.lang.Object, 1) objects_array[0] = filter_list return method.invoke(j_filter_factory, objects_array)
def ingest(self, url, *indices, ingest_options=None): """ Ingest from URL. If this is a directory, this method will recursively search for valid files to ingest in the directory. This will iterate through registered IngestFormatPlugins to find one that works for a given file. Args: url (str): The URL for data to read and ingest into this data store. *indices (pygw.index.index.Index): Index to ingest into. ingest_options: Options for ingest (Not yet supported). """ # TODO: Ingest Options if ingest_options: raise NotImplementedError() assert isinstance(url, str) n = len(indices) j_index_class = geowave_pkg.core.store.api.Index j_index_arr = java_gateway.new_array(j_index_class, n) for idx, name in enumerate(indices): j_index_arr[idx] = name._java_ref java_url = java_gateway.jvm.java.net.URL(url) self._java_ref.ingest(java_url, ingest_options, j_index_arr)
def _to_java(self, value): j_arr = java_gateway.new_array(self._j_class, len(value)) for i in range(len(value)): if value[i] is None: continue j_arr[i] = self.subtype._to_java(value[i]) return j_arr
def to_java_array(java_class, objects): n = len(objects) j_arr = java_gateway.new_array(java_class, n) for idx, obj in enumerate(objects): if not isinstance(obj, GeoWaveObject) or not obj.is_instance_of(java_class): print(obj, objects, java_class) raise AttributeError("Given object is not compatible with the given class.") j_arr[idx] = obj.java_ref() return j_arr
def function(self, name, expressions): """ Constructs an expression by passing a set of expressions to an expression function. Args: name (str): The name of the function. expressions (list of Expression): The expressions to use in the function. Returns: An Expression which represents the result of the function. """ j_expressions = java_gateway.new_array(java_pkg.org.opengis.filter.expression.Expression, len(expressions)) for idx, expression in enumerate(expressions): j_expressions[idx] = expression return self._java_ref.function(name, j_expressions)
def data_ids(self, data_ids): """ Constrain a query by data IDs. Args: data_ids (list of bytes): The data IDs to constrain by. Returns: A `pygw.query.query_constraints.QueryConstraints` with the given data ids. """ byte_array_class = JavaClass("[B", java_gateway._gateway_client) j_data_ids = java_gateway.new_array(byte_array_class, len(data_ids)) for idx, data_id in enumerate(data_ids): j_data_ids[idx] = _pbat.to_java(data_id) j_qc = self._java_ref.dataIds(j_data_ids) return QueryConstraints(j_qc)
def id(self, fids): """ Constructs a filter that matches a set of feature IDs. Args: fids (list of str): The list of feature IDs to match. Returns: A Filter with the given feature IDs. """ j_fids = java_gateway.new_array(java_pkg.org.opengis.filter.identity.FeatureId, len(fids)) for idx, fid in enumerate(fids): if isinstance(fid, str): j_fids[idx] = self.feature_id(fid) else: j_fids[idx] = fid return self._java_ref.id(j_fids)
def add_type(self, type_adapter, *initial_indices): """ Add this type to the data store. This only needs to be called one time per type. Args: type_adapter (pygw.base.data_type_adapter.DataTypeAdapter): The data type adapter to add to the data store. *initial_indices (pygw.index.index.Index): The initial indices for this type. """ assert isinstance(type_adapter, DataTypeAdapter) n = len(initial_indices) j_index_class = geowave_pkg.core.store.api.Index j_index_arr = java_gateway.new_array(j_index_class, n) for idx, py_obj in enumerate(initial_indices): j_index_arr[idx] = py_obj._java_ref self._java_ref.addType(type_adapter._java_ref, j_index_arr)
def add_index(self, type_name, *indices): """ Add new indices for the given type. If there is data in other indices for this type, for consistency it will need to copy all of the data into the new indices, which could be a long process for lots of data. Args: type_name (str): Name of data type to register indices to. *indices (pygw.index.index.Index): Index to add. """ assert isinstance(type_name, str) n = len(indices) j_index_class = geowave_pkg.core.store.api.Index j_index_arr = java_gateway.new_array(j_index_class, n) for idx, py_obj in enumerate(indices): j_index_arr[idx] = py_obj._java_ref self._java_ref.addIndex(type_name, j_index_arr)
def _build_array(self, value): return java_gateway.new_array(self._j_class, len(value))