def test_union(self): # Build patches as in dissolved.py stub = geometry_grpc.GeometryOperatorsStub(self.channel) r = partial(random.uniform, -20.0, 20.0) serviceSpatialReference = SpatialReferenceData(wkid=4326) points = [Point(r(), r()) for i in range(10000)] spots = [p.buffer(2.5) for p in points] service_multipoint = GeometryBagData( spatial_reference=serviceSpatialReference, geometry_encoding_type=GeometryEncodingType.Value('wkb')) shape_start = datetime.datetime.now() patches = cascaded_union(spots) # because shapely is non-simple we need to simplify it for this to be a fair comparison service_multipoint.geometry_binaries.extend([patches.wkb]) opRequestOuter = OperatorRequest( left_geometry_bag=service_multipoint, operator_type=ServiceOperatorType.Value('Simplify'), operation_spatial_reference=serviceSpatialReference, results_encoding_type=GeometryEncodingType.Value('wkb')) response = stub.ExecuteOperation(opRequestOuter) patches = wkbloads(response.geometry_bag.geometry_binaries[0]) shape_end = datetime.datetime.now() shape_delta = shape_end - shape_start shape_microseconds = int(shape_delta.total_seconds() * 1000) print(shape_microseconds) print(patches.wkt) spots_wkb = [s.wkb for s in spots] geometryBagData = GeometryBagData() geometryBagData.geometry_binaries.extend(spots_wkb) geometryBagData.geometry_encoding_type = GeometryEncodingType.Value( 'wkb') opRequestUnion = OperatorRequest( left_geometry_bag=geometryBagData, operator_type=ServiceOperatorType.Value('Union')) epl_start = datetime.datetime.now() response = stub.ExecuteOperation(opRequestUnion) unioned_result = wkbloads(response.geometry_bag.geometry_binaries[0]) epl_end = datetime.datetime.now() epl_delta = epl_end - epl_start epl_microseconds = int(epl_delta.total_seconds() * 1000) # TODO investigate why dev machine is faster for epl and slower for shapely and the alternative is true for test machines (memory limits?) # self.assertGreater(shape_microseconds, epl_microseconds) # self.assertGreater(shape_microseconds * 0.75, epl_microseconds) self.assertAlmostEqual(patches.area, unioned_result.area, 8)
def load_geo(cls, wkb): """Load geometry into browse record after read was done""" if isinstance(wkb, BaseGeometry): return wkb return wkbloads(wkb, hex=True) if wkb else False
def load_geo(cls, wkb): """Load geometry into browse record after read was done""" return wkbloads(wkb.decode('hex')) if wkb else False
def load_geo(self, wkb): """Load geometry into browse record after read was done""" return wkb and wkbloads(wkb.decode('hex')) or False
def load_geo(cls, wkb): """Load geometry into browse record after read was done""" return wkbloads(wkb, hex=True) if wkb else False
def test_multipoint(self): stub = geometry_grpc.GeometryOperatorsStub(self.channel) serviceSpatialReference = SpatialReferenceData(wkid=4326) outputSpatialReference = SpatialReferenceData(wkid=3857) multipoints_array = [] for longitude in range(-180, 180, 10): for latitude in range(-80, 80, 10): multipoints_array.append((longitude, latitude)) multipoint = MultiPoint(multipoints_array) serviceGeomPolyline = GeometryBagData( geometry_strings=[multipoint.wkt], geometry_encoding_type=GeometryEncodingType.Value('wkt'), spatial_reference=serviceSpatialReference) opRequestProject = OperatorRequest( left_geometry_bag=serviceGeomPolyline, operator_type=ServiceOperatorType.Value('Project'), operation_spatial_reference=outputSpatialReference) opRequestOuter = OperatorRequest( left_nested_request=opRequestProject, operator_type=ServiceOperatorType.Value('Project'), operation_spatial_reference=serviceSpatialReference, results_encoding_type=GeometryEncodingType.Value('wkt')) print("make project request") response = stub.ExecuteOperation(opRequestOuter) print("Client received project response:\n", response) round_trip_result_wkt = loads( response.geometry_bag.geometry_strings[0]) opRequestOuter = OperatorRequest( left_nested_request=opRequestProject, operator_type=ServiceOperatorType.Value('Project'), operation_spatial_reference=serviceSpatialReference, results_encoding_type=GeometryEncodingType.Value('wkb')) response = stub.ExecuteOperation(opRequestOuter) round_trip_result = wkbloads( response.geometry_bag.geometry_binaries[0]) self.assertIsNotNone(round_trip_result) max_diff_lat = 0.0 max_diff_lon = 0.0 for index, projected_point in enumerate(round_trip_result): original_point = multipoint[index] if math.fabs(original_point.x - projected_point.x) > max_diff_lon: max_diff_lon = math.fabs(original_point.x - projected_point.x) if math.fabs(original_point.y - projected_point.y) > max_diff_lat: max_diff_lat = math.fabs(original_point.y - projected_point.y) self.assertLess(math.fabs(original_point.x - projected_point.x), 0.0000001) self.assertLess(math.fabs(original_point.y - projected_point.y), 0.0000001) for index, projected_point in enumerate(round_trip_result_wkt): original_point = multipoint[index] if math.fabs(original_point.x - projected_point.x) > max_diff_lon: max_diff_lon = math.fabs(original_point.x - projected_point.x) if math.fabs(original_point.y - projected_point.y) > max_diff_lat: max_diff_lat = math.fabs(original_point.y - projected_point.y) self.assertLess(math.fabs(original_point.x - projected_point.x), 0.00000001) self.assertLess(math.fabs(original_point.y - projected_point.y), 0.00000001)