コード例 #1
0
    def test_gpkg_test_connection_interlis_no_ladm_col_models(self):
        print("\nINFO: Validate test_connection() for GeoPackage (Interlis, no LADM-COL models)...")

        db = get_gpkg_conn('interlis_no_ladm_col_models_gpkg')
        res, code, msg = db.test_connection()
        self.assertFalse(res, msg)
        self.assertEqual(code, EnumTestConnectionMsg.NO_LADM_MODELS_FOUND_IN_SUPPORTED_VERSION)
コード例 #2
0
 def test_gpkg_test_connection_required_models_success(self):
     print("\nINFO: Validate test_connection() for GeoPackage (required models (success): survey and snr)...")
     db = get_gpkg_conn('test_ladm_survey_model_gpkg')
     res, code, msg = db.test_connection(required_models=[LADMNames.SURVEY_MODEL_KEY,
                                                          LADMNames.SNR_DATA_SUPPLIES_MODEL_KEY])
     self.assertTrue(res, msg)
     self.assertEqual(code, EnumTestConnectionMsg.DB_WITH_VALID_LADM_COL_STRUCTURE)
コード例 #3
0
    def test_gpkg_test_connection_existing_file_no_interlis(self):
        print("\nINFO: Validate test_connection() for GeoPackage (existing file, no Interlis)...")

        db = get_gpkg_conn('no_interlis_gpkg')
        res, code, msg = db.test_connection()
        self.assertFalse(res, msg)
        self.assertEqual(code, EnumTestConnectionMsg.INTERLIS_META_ATTRIBUTES_NOT_FOUND)
コード例 #4
0
    def test_gpkg_test_connection_existing_file_schema_import(self):
        print("\nINFO: Validate test_connection() for GeoPackage (existing file, Schema Import)...")

        db = get_gpkg_conn('no_interlis_gpkg')
        res, code, msg = db.test_connection(EnumTestLevel.SCHEMA_IMPORT)
        self.assertTrue(res, msg)
        self.assertEqual(code, EnumTestConnectionMsg.CONNECTION_TO_SERVER_SUCCESSFUL)
コード例 #5
0
    def test_boundaries_are_not_split(self):
        print('\nINFO: Validating boundaries are not split...')
        gpkg_path = get_test_copy_path('db/static/gpkg/quality_validations.gpkg')
        self.db_gpkg = get_gpkg_conn('tests_quality_validations_gpkg')
        names = self.db_gpkg.names
        names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure
        names.T_ILI_TID_F = 't_ili_tid'  # Static label is set because the database does not have the ladm structure

        uri_bad_boundary = gpkg_path + '|layername={layername}'.format(layername='bad_boundary')
        uri_bbox_boundary = gpkg_path + '|layername={layername}'.format(layername='bbox_intersect_boundary')
        uri_good_boundary = gpkg_path + '|layername={layername}'.format(layername='good_boundary')
        bad_boundary_layer = QgsVectorLayer(uri_bad_boundary, 'bad_boundary', 'ogr')
        bbox_boundary_layer = QgsVectorLayer(uri_bbox_boundary, 'bbox_intersect_boundary', 'ogr')
        good_boundary_layer = QgsVectorLayer(uri_good_boundary, 'good_boundary', 'ogr')

        bad_boundary_errors = self.geometry.get_boundaries_connected_to_single_boundary(names, bad_boundary_layer)
        bad_boundary_errors_list = [item for item in bad_boundary_errors]
        self.assertEqual(len(bad_boundary_errors_list), 4)
        self.assertEqual([2, 3, 6, 7], [f['t_id'] for f in bad_boundary_errors])

        bbox_boundary_errors = self.geometry.get_boundaries_connected_to_single_boundary(names, bbox_boundary_layer)
        bbox_boundary_errors_list = [item for item in bbox_boundary_errors]
        self.assertEqual(len(bbox_boundary_errors_list), 9)
        self.assertEqual([39185, 39193, 39207, 39209, 39210, 39231, 39232, 48767, 48768], [f['t_id'] for f in bbox_boundary_errors_list])

        good_boundary_errors = self.geometry.get_boundaries_connected_to_single_boundary(names, good_boundary_layer)
        good_boundary_errors_list = [item for item in good_boundary_errors]
        self.assertEqual(len(good_boundary_errors_list), 0)
コード例 #6
0
    def test_polygons_must_be_covered_by_lines(self):
        print('\nINFO: Validating polygons must be covered by lines...')

        gpkg_path = get_test_copy_path('db/static/gpkg/topology_cases.gpkg')
        self.db_gpkg = get_gpkg_conn('topology_cases_gpkg')
        names = self.db_gpkg.names
        names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure

        diff_geom = [
            [
                'MultiLineString ((780300.30731518880929798 1225605.22174088703468442, 780297.95234157983213663 1225599.8581298291683197, 780292.44514157995581627 1225602.31722982972860336, 780294.34505024075042456 1225606.57437412883155048))'
            ],
            [
                'MultiLineString ((780300.30731518880929798 1225605.22174088703468442, 780297.95234157983213663 1225599.8581298291683197, 780292.44514157995581627 1225602.31722982972860336, 780294.34505024075042456 1225606.57437412883155048))'
            ],
            [
                'MultiLineString ((780309.73902403307147324 1225602.49830744392238557, 780308.30989155941642821 1225603.05408118362538517, 780307.64825615496374667 1225603.95390533376485109),(780310.01870060083456337 1225599.16431454825215042, 780310.03014361101668328 1225598.66082209814339876, 780311.16639214521273971 1225598.61655267467722297))'
            ],
            [
                'MultiLineString ((780307.7805832359008491 1225598.39616793626919389, 780307.60049424471799284 1225599.58559290133416653),(780308.69099051796365529 1225598.27522822353057563, 780307.7805832359008491 1225598.39616793626919389),(780315.57867445563897491 1225608.45340170268900692, 780315.45555392769165337 1225607.63259818265214562, 780314.78905752801802009 1225607.92419035756029189),(780317.62428020488005131 1225603.16991792898625135, 780318.36674970726016909 1225602.84235785435885191, 780318.29131162946578115 1225603.45340628433041275))'
            ],
            [
                'MultiLineString ((780306.77080396702513099 1225605.06540775927715003, 780306.64257034030742943 1225605.91234613093547523, 780307.906158416881226 1225605.63026071945205331),(780314.52926436136476696 1225599.74590416136197746, 780312.94133939070161432 1225600.03702373942360282, 780312.34155925654340535 1225600.40004855743609369),(780312.43979134678374976 1225599.65884278574958444, 780314.52926436136476696 1225599.74590416136197746),(780318.10209554550237954 1225604.98605656484141946, 780317.2287368115503341 1225605.14484906173311174, 780316.19658558059018105 1225606.12406946043483913))'
            ], '',
            [
                'MultiLineString ((871560.66490000020712614 1554564.43640000000596046, 871561.29310000035911798 1554568.61969999969005585, 871565.18800000008195639 1554569.14470000006258488, 871582.36809999961405993 1554569.08310000039637089, 871586.65579999983310699 1554568.74300000071525574, 871586.17630000039935112 1554559.7443000003695488, 871586.15149999968707561 1554558.96719999983906746))',
                'MultiLineString ((871581.97680000029504299 1554559.16310000047087669, 871583.06890000030398369 1554559.11189999990165234, 871586.15149999968707561 1554558.96719999983906746),(871586.15149999968707561 1554558.96719999983906746, 871585.68250000011175871 1554551.27449999935925007, 871585.4917000001296401 1554549.15570000000298023, 871584.2698999997228384 1554549.2476000003516674, 871576.33000000007450581 1554549.84439999982714653, 871561.16789999976754189 1554551.16310000047087669, 871545.42370000015944242 1554551.99960000067949295, 871546.30889999959617853 1554566.21570000052452087, 871560.66490000020712614 1554564.43640000000596046))'
            ]
        ]

        for i in range(len(diff_geom)):
            uri_polygon = gpkg_path + '|layername={layername}_case{case}'.format(
                layername='polygon', case=i + 1)
            uri_lines = gpkg_path + '|layername={layername}_case{case}'.format(
                layername='lines', case=i + 1)
            polygon_layer = QgsVectorLayer(uri_polygon,
                                           'polygon_layer_{}'.format(i + 1),
                                           'ogr')
            lines_layer = QgsVectorLayer(uri_lines,
                                         'lines_layer_{}'.format(i + 1), 'ogr')

            polygon_as_lines_layer = processing.run(
                "ladm_col:polygonstolines", {
                    'INPUT': polygon_layer,
                    'OUTPUT': 'TEMPORARY_OUTPUT'
                })['OUTPUT']
            diff_plot_boundary = self.geometry.difference_plot_boundary(
                polygon_as_lines_layer, lines_layer, 'fid')

            if diff_plot_boundary is not None:
                if len(diff_plot_boundary) > 0:
                    for element in range(len(diff_plot_boundary)):
                        self.assertIn(
                            diff_plot_boundary[element]['geometry'].asWkt(),
                            diff_geom[i],
                            'case_{}, element_{}'.format(i + 1, element))
                else:  # Case 6
                    self.assertEqual('', diff_geom[i], 'case_{}'.format(i + 1))
 def test_gpkg_test_connection(self):
     print(
         "\nINFO: Validate test_connection() for GeoPackage (survey model: OK!)..."
     )
     db = get_gpkg_conn('test_ladm_survey_model_gpkg')
     res, code, msg = db.test_connection()
     self.assertTrue(res, msg)
     self.assertEqual(
         code, EnumTestConnectionMsg.DB_WITH_VALID_LADM_COL_STRUCTURE)
 def test_gpkg_test_connection_required_models_error(self):
     print(
         "\nINFO: Validate test_connection() for GeoPackage (required models (error): ant)..."
     )
     db = get_gpkg_conn('test_ladm_survey_model_gpkg')
     res, code, msg = db.test_connection(
         models={REQUIRED_MODELS: [LADMNames.VALUATION_MODEL_KEY]})
     self.assertFalse(res, msg)
     self.assertEqual(code,
                      EnumTestConnectionMsg.REQUIRED_LADM_MODELS_NOT_FOUND)
コード例 #9
0
 def test_gpkg_test_connection_required_models_error(self):
     print(
         "\nINFO: Validate test_connection() for GeoPackage (required models (error): ant)..."
     )
     db = get_gpkg_conn('test_ladm_operation_model_gpkg')
     res, code, msg = db.test_connection(
         required_models=[LADMNames.ANT_MODEL_PREFIX])
     self.assertFalse(res, msg)
     self.assertEqual(code,
                      EnumTestConnectionMsg.REQUIRED_LADM_MODELS_NOT_FOUND)
コード例 #10
0
 def test_gpkg_test_connection_required_models_success(self):
     print(
         "\nINFO: Validate test_connection() for GeoPackage (required models (success): operation and snr)..."
     )
     db = get_gpkg_conn('test_ladm_operation_model_gpkg')
     res, code, msg = db.test_connection(required_models=[
         LADMNames.OPERATION_MODEL_PREFIX, LADMNames.SNR_DATA_MODEL_PREFIX
     ])
     self.assertTrue(res, msg)
     self.assertEqual(
         code, EnumTestConnectionMsg.DB_WITH_VALID_LADM_COL_STRUCTURE)
コード例 #11
0
    def test_gpkg_get_models(self):
        print("\nINFO: Validate get models method() in geopackage...")
        expected_dict = {
            'test_ladm_all_models_gpkg': [
                LADMNames.SUPPORTED_ANT_MODEL,
                LADMNames.SUPPORTED_VALUATION_MODEL,
                LADMNames.SUPPORTED_REFERENCE_CARTOGRAPHY,
                LADMNames.SUPPORTED_SUPPLIES_MODEL,
                LADMNames.SUPPORTED_SUPPLIES_INTEGRATION_MODEL,
                LADMNames.SUPPORTED_SNR_DATA_MODEL,
                LADMNames.SUPPORTED_CADASTRAL_FORM_MODEL,
                LADMNames.SUPPORTED_OPERATION_MODEL,
                LADMNames.SUPPORTED_ISO_CARTESIAN_COORDINATES,
                LADMNames.SUPPORTED_LADM_MODEL
            ],
            'test_ladm_integration_gpkg': [
                LADMNames.SUPPORTED_SNR_DATA_MODEL,
                LADMNames.SUPPORTED_SUPPLIES_INTEGRATION_MODEL,
                LADMNames.SUPPORTED_SUPPLIES_MODEL,
                LADMNames.SUPPORTED_ISO_CARTESIAN_COORDINATES,
                LADMNames.SUPPORTED_LADM_MODEL
            ],
            'test_ladm_operation_model_gpkg': [
                LADMNames.SUPPORTED_OPERATION_MODEL,
                LADMNames.SUPPORTED_SNR_DATA_MODEL,
                LADMNames.SUPPORTED_SUPPLIES_INTEGRATION_MODEL,
                LADMNames.SUPPORTED_SUPPLIES_MODEL,
                LADMNames.SUPPORTED_ISO_CARTESIAN_COORDINATES,
                LADMNames.SUPPORTED_LADM_MODEL
            ],
            'test_ladm_cadastral_manager_data_gpkg': [
                LADMNames.SUPPORTED_SUPPLIES_MODEL,
                LADMNames.SUPPORTED_ISO_CARTESIAN_COORDINATES
            ]
        }

        for gpkg_schema_name in expected_dict:
            self.db_gpkg = get_gpkg_conn(gpkg_schema_name)

            model_names = self.db_gpkg.get_models()
            self.assertEqual(set(expected_dict[gpkg_schema_name]),
                             set(model_names))
コード例 #12
0
    def test_lines_must_be_covered_by_polygons(self):
        print('\nINFO: Validating lines must be covered by polygons...')

        gpkg_path = get_test_copy_path('db/static/gpkg/topology_cases.gpkg')
        self.db_gpkg = get_gpkg_conn('topology_cases_gpkg')
        names = self.db_gpkg.names
        names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure

        diff_geom = [
            '', '',
            'MultiLineString ((780309.73902403307147324 1225602.49830744392238557, 780307.83351406815927476 1225602.05170354596339166, 780307.64825615496374667 1225603.95390533376485109))',
            '',
            'MultiLineString ((780318.10209554550237954 1225604.98605656484141946, 780317.50662368256598711 1225605.92888701660558581, 780316.19658558059018105 1225606.12406946043483913))',
            'MultiLineString ((780314.52926436136476696 1225599.74590416136197746, 780312.94133939070161432 1225600.03702373942360282, 780310.92996776115614921 1225601.25443288357928395, 780310.00367819482926279 1225599.82530040992423892, 780310.03014361101668328 1225598.66082209814339876, 780312.06798065674956888 1225598.5814258495811373, 780311.35341442003846169 1225599.61357708042487502, 780314.52926436136476696 1225599.74590416136197746))',
            ''
        ]

        for i in range(len(diff_geom)):
            uri_polygon = gpkg_path + '|layername={layername}_case{case}'.format(
                layername='polygon', case=i + 1)
            uri_lines = gpkg_path + '|layername={layername}_case{case}'.format(
                layername='lines', case=i + 1)
            polygon_layer = QgsVectorLayer(uri_polygon,
                                           'polygon_layer_{}'.format(i + 1),
                                           'ogr')
            lines_layer = QgsVectorLayer(uri_lines,
                                         'lines_layer_{}'.format(i + 1), 'ogr')

            polygon_as_lines_layer = processing.run(
                "ladm_col:polygonstolines", {
                    'INPUT': polygon_layer,
                    'OUTPUT': 'TEMPORARY_OUTPUT'
                })['OUTPUT']
            diff_boundary_plot = self.geometry.difference_boundary_plot(
                lines_layer, polygon_as_lines_layer, 'fid')

            if diff_boundary_plot is not None:
                if len(diff_boundary_plot) > 0:
                    self.assertEqual(diff_boundary_plot[0]['geometry'].asWkt(),
                                     diff_geom[i], 'case_{}'.format(i + 1))
                else:
                    self.assertEqual('', diff_geom[i], 'case_{}'.format(i + 1))
コード例 #13
0
    def test_boundary_dangles(self):
        print('\nINFO: Validating boundary_dangles...')
        gpkg_path = get_test_copy_path('db/static/gpkg/geometry_utils.gpkg')
        self.db_gpkg = get_gpkg_conn('tests_geometry_util_gpkg')
        names = self.db_gpkg.names
        names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure

        uri = gpkg_path + '|layername={layername}'.format(layername='overlapping_lines')
        boundary_layer = QgsVectorLayer(uri, 'dangles', 'ogr')

        features = [feature for feature in boundary_layer.getFeatures()]
        self.assertEqual(len(features), 15)

        end_points, dangle_ids = self.geometry.get_dangle_ids(boundary_layer)
        self.assertEqual(len(dangle_ids), 19)

        boundary_ids = [feature[names.T_ID_F] for feature in end_points.getFeatures(dangle_ids)]
        boundary_ids.sort()
        expected_boundary_ids = [4, 4, 5, 6, 6, 7, 8, 10, 10, 13, 14, 325, 325, 334, 334, 335, 336, 336, 337]

        self.assertEqual(boundary_ids, expected_boundary_ids)
コード例 #14
0
    def test_pair_boundary_plot(self):
        print('\nValidating pairs boundary-plot')
        gpkg_path = get_test_copy_path(
            'db/static/gpkg/quality_validations.gpkg')
        self.db_gpkg = get_gpkg_conn('tests_quality_validations_gpkg')
        self.names = self.db_gpkg.names
        self.names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure

        uri = gpkg_path + '|layername={layername}'.format(
            layername='topology_boundaries')
        boundary_layer = QgsVectorLayer(uri, 'topology_boundaries', 'ogr')

        uri = gpkg_path + '|layername={layername}'.format(
            layername='topology_plots')
        plot_layer = QgsVectorLayer(uri, 'topology_plots', 'ogr')

        result1, result2 = GeometryUtils().get_pair_boundary_plot(
            boundary_layer, plot_layer, self.names.T_ID_F, use_selection=False)

        self.assertEqual(result1, [(1, 3), (3, 3)])

        self.assertEqual(result2, [(1, 4)])
コード例 #15
0
    def test_find_vertices(self):
        print('\nINFO: Validating search for missing vertices...')

        gpkg_path = get_test_copy_path('db/static/gpkg/topology_cases.gpkg')
        self.db_gpkg = get_gpkg_conn('topology_cases_gpkg')
        names = self.db_gpkg.names
        names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure

        # Map between case number and number of vertices that should be added
        # For instance, the 4th case (reflected in the layer's name) should
        # have 6 vertices found
        vertices_test_values = [2, 2, 2, 6, 4, 0]

        for i in range(len(vertices_test_values)):
            uri_polygon = gpkg_path + '|layername={layername}_case{case}'.format(
                layername='polygon', case=i + 1)
            uri_lines = gpkg_path + '|layername={layername}_case{case}'.format(
                layername='lines', case=i + 1)
            polygon_layer = QgsVectorLayer(uri_polygon,
                                           'polygon_layer_{}'.format(i + 1),
                                           'ogr')
            lines_layer = QgsVectorLayer(uri_lines,
                                         'lines_layer_{}'.format(i + 1), 'ogr')

            geom_polygon = polygon_layer.getFeature(1).geometry()
            init_vertex_geom = [vertex for vertex in geom_polygon.vertices()]

            # We don't overwrite the original layer, changes are made on a copy
            mod_polygon_layer = self.geometry.add_topological_vertices(
                polygon_layer, lines_layer)

            geom_polygon = mod_polygon_layer.getFeature(1).geometry()
            adjusted_vertex_geom = [
                vertex for vertex in geom_polygon.vertices()
            ]

            num_vertices_added = len(adjusted_vertex_geom) - len(
                init_vertex_geom)
            self.assertEqual(num_vertices_added, vertices_test_values[i])
コード例 #16
0
 def get_connector(cls) -> DBConnector:
     return get_gpkg_conn('test_ladm_survey_model_gpkg')
 def setUpClass(cls):
     print("INFO: Restoring databases to be used")
     restore_schema('test_ladm_reference_cartography')
     cls.db_pg = get_pg_conn('test_ladm_reference_cartography')
     cls.db_gpkg = get_gpkg_conn('test_ladm_reference_cartography_gpkg')
コード例 #18
0
 def setUpClass(cls):
     print("INFO: Restoring databases to be used")
     restore_schema('test_ladm_ant')
     cls.db_pg = get_pg_conn('test_ladm_ant')
     cls.db_gpkg = get_gpkg_conn('test_ladm_ant_gpkg')
コード例 #19
0
    def test_split_by_selected_boundary(self):
        print('\nINFO: Validation of the definition of selected boundary ...')

        gpkg_path = get_test_copy_path(
            'db/static/gpkg/adjust_boundaries_cases.gpkg')
        self.db_gpkg = get_gpkg_conn('adjust_boundaries_cases_gpkg')
        names = self.db_gpkg.names
        names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure

        test_result = [{
            'selected_ids': [1],
            'boundaries_to_del': [1, 2, 3, 4],
            'geoms': [
                'LineString (882256.9922020563390106 1545352.94816972548142076, 883830.40917081397492439 1545368.68233941309154034, 885435.29447894683107734 1545352.94816972548142076, 887291.92650208086706698 1545337.21400003810413182, 888881.07764052611310035 1545463.08735753851942718)'
            ]
        }, {
            'selected_ids': [1],
            'boundaries_to_del': [1, 2],
            'geoms': [
                'LineString (882325.469107756158337 1544955.88267589989118278, 883209.64509183121845126 1544960.13352197711355984, 884510.40399148012511432 1544985.6385984409134835, 885547.61043433740269393 1544964.3843680543359369, 886822.86425752262584865 1544977.13690628623589873, 887889.82662292092572898 1544989.88944451813586056, 888612.47045605920720845 1545002.64198275003582239)'
            ]
        }, {
            'selected_ids': [1],
            'boundaries_to_del': [1, 2, 3],
            'geoms': [
                'LineString (886476.29300758719909936 1544161.06105313077569008, 882415.14798706094734371 1544041.61561135039664805, 882407.18495760892983526 1541724.37404081481508911, 887200.92868772032670677 1541764.18918807501904666)',
                'LineString (886476.29300758719909936 1544161.06105313077569008, 889390.76178702362813056 1543165.68237162916921079, 887200.92868772032670677 1541764.18918807501904666)',
                'LineString (887200.92868772032670677 1541764.18918807501904666, 886476.29300758719909936 1544161.06105313077569008)'
            ]
        }, {
            'selected_ids': [3],
            'boundaries_to_del': [1, 2, 3],
            'geoms': [
                'LineString (886476.29300758719909936 1544161.06105313077569008, 882415.14798706094734371 1544041.61561135039664805, 882407.18495760892983526 1541724.37404081481508911, 887200.92868772032670677 1541764.18918807501904666)',
                'LineString (886476.29300758719909936 1544161.06105313077569008, 889390.76178702362813056 1543165.68237162916921079, 887894.38694565510377288 1542208.00247315340675414, 887200.92868772032670677 1541764.18918807501904666)'
            ]
        }, {
            'selected_ids': [1],
            'boundaries_to_del': [1, 2, 3],
            'geoms': [
                'LineString (882709.45987063564825803 1543510.21952517866156995, 882696.0032627055188641 1542761.13501706859096885, 883485.45759460597764701 1543057.18039153120480478, 882709.45987063564825803 1543510.21952517866156995)',
                'LineString (883485.45759460597764701 1543057.18039153120480478, 884898.40142726874910295 1543084.09360739146359265)',
                'LineString (884898.40142726874910295 1543084.09360739146359265, 885629.54379147209692746 1543640.30006850324571133, 885719.25451100617647171 1542711.79412132478319108, 884898.40142726874910295 1543084.09360739146359265)'
            ]
        }, {
            'selected_ids': [2],
            'boundaries_to_del': [1, 2],
            'geoms': [
                'LineString (882696.91113005892839283 1543128.55981796747073531, 883485.45759460597764701 1543057.18039153120480478, 884898.40142726874910295 1543084.09360739146359265)'
            ]
        }, {
            'selected_ids': [1],
            'boundaries_to_del': [1, 2],
            'geoms': [
                'LineString (882376.98617732501588762 1543885.65919923176988959, 881339.55751997174229473 1543276.52677656547166407, 882234.22076576261315495 1542448.48738950374536216)'
            ]
        }, {
            'selected_ids': [1],
            'boundaries_to_del': [1, 2, 3, 4],
            'geoms': [
                'LineString (895937.47771990788169205 1543691.07968750013969839, 895937.47771990788169205 1543987.82934027793817222, 896479.9233217597939074 1543987.82934027793817222, 896479.9233217597939074 1543691.07968750013969839, 895937.47771990788169205 1543691.07968750013969839)'
            ]
        }, {
            'selected_ids': [8],
            'boundaries_to_del': [1, 2, 3, 4, 5, 6, 7, 8],
            'geoms': [
                'LineString (895922.15344387735240161 1545423.63106414745561779, 895823.74850363796576858 1545312.72245558886788785, 895753.01430986321065575 1545231.0768567833583802, 895752.70520490442868322 1545118.35534420749172568, 895755.45756576466374099 1545004.08130264561623335, 895750.58388843457214534 1544903.72545119561254978, 895751.76962125208228827 1544777.10258481604978442, 895944.93307849601842463 1544785.83842549938708544)',
                'LineString (895922.15344387735240161 1545423.63106414745561779, 896065.97630945523269475 1545327.50076097156852484, 896159.22516733291558921 1545234.59747773432172835, 896159.51394954684656113 1544779.07535220449790359, 895944.93307849601842463 1544785.83842549938708544)'
            ]
        }]

        for i in range(len(test_result)):
            uri = gpkg_path + '|layername=boundary_case_{case}'.format(case=i +
                                                                       1)
            boundary_layer = QgsVectorLayer(
                uri, 'boundary_layer_{case}'.format(case=i + 1), 'ogr')
            test_selected_ids = test_result[i]['selected_ids']
            #boundary_layer.selectByIds(selected_ids)
            new_geometries, boundaries_to_del_unique_ids = self.geometry.fix_selected_boundaries(
                names,
                boundary_layer,
                names.T_ID_F,
                selected_ids=test_selected_ids)
            self.assertEqual(
                boundaries_to_del_unique_ids,
                test_result[i]['boundaries_to_del'],
                'Boundaries to be deleted are not valid: case {case}'.format(
                    case=i + 1))

            for new_geom in new_geometries:
コード例 #20
0
    def _test_get_overlapping_lines(self):
        print('\nINFO: Validating overlaps in boundaries...')
        gpkg_path = get_test_copy_path('db/static/gpkg/geometry_utils.gpkg')
        self.db_gpkg = get_gpkg_conn('tests_geometry_util_gpkg')
        names = self.db_gpkg.names
        names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure

        uri = gpkg_path + '|layername={layername}'.format(
            layername='overlapping_lines')
        boundary_overlap_layer = QgsVectorLayer(uri, 'test_overlapping_lines',
                                                'ogr')
        self.assertEqual(boundary_overlap_layer.featureCount(), 15)

        overlapping_lines = self.geometry.get_overlapping_lines(
            boundary_overlap_layer)
        self.assertNotEqual(overlapping_lines, dict())

        error_line_layer = overlapping_lines[
            'native:extractbyexpression_3:Intersected_Lines']
        error_point_layer = overlapping_lines[
            'native:deleteduplicategeometries_1:Intersected_Points']

        self.assertEqual(error_point_layer.featureCount(),
                         20)  # 20: len(expected_point_overlaps)
        self.assertEqual(error_line_layer.featureCount(), 5)

        point_features = error_point_layer.getFeatures()
        line_features = error_line_layer.getFeatures()

        # First, check point overlaps
        # For point overlaps, we don't rely on t_id pairs, because duplicated geometries are removed randomly,
        # therefore we are only interested in geometries (as WKTs).
        expected_point_overlaps = [
            'Point (963384.55712854664307088 1077823.99900980317033827)',
            'Point (963750.28136727144010365 1077824.19025488453917205)',
            'Point (963662.21440408274065703 1077708.90435272408649325)',
            'Point (963849.37875852338038385 1077949.20776149653829634)',
            'Point (964211.2347710223402828 1077618.29701916221529245)',
            'Point (963651.61653553508222103 1077966.0537187303416431)',
            'Point (964079.46952913235872984 1077829.37777462997473776)',
            'Point (964309.98692709254100919 1077617.49567248369567096)',
            'Point (964144.41837483353447169 1077577.06614228105172515)',
            'Point (963905.69162506482098252 1077713.75645868084393442)',
            'Point (963850.90352329798042774 1077652.23999353917315602)',
            'Point (964081.01700186752714217 1077722.2743631626944989)',
            'Point (963880.39959512907080352 1077685.35838998109102249)',
            'Point (963801.72997597197536379 1077798.46595053421333432)',
            'Point (963255.32157539459876716 1077724.74916282831691206)',
            'Point (964213.72614089539274573 1077962.10928706941194832)',
            'Point (963759.37523004529066384 1078021.79097451153211296)',
            'Point (963643.395574557245709 1077747.43814651435241103)',
            'Point (963926.86899802810512483 1077925.5301883143838495)',
            'Point (963980.77503829856868833 1077802.31638198206201196)'
        ]
        for point in point_features:
            self.assertIn(point.geometry().asWkt(), expected_point_overlaps)

        # Now, check line overlaps
        line_overlaps = dict()

        def insert_into_res(ids, geometry):
            """
            Local function to append a geometry into a list for each pair of ids
            """
            pair = "{}-{}".format(min(ids), max(ids))
            if pair not in line_overlaps:
                line_overlaps[pair] = [geometry]
            else:  # Pair is in dict already
                line_overlaps[pair].append(geometry)

        for line in line_features:
            insert_into_res([line[names.T_ID_F], line[names.T_ID_F + '_2']],
                            line.geometry().asWkt())

        expected_line_overlaps = {
            '7-15': [
                'MultiLineString ((964213.72614089539274573 1077962.10928706941194832, 963759.37523004529066384 1078021.79097451153211296))'
            ],
            '5-6': [
                'MultiLineString ((963926.86899802810512483 1077925.5301883143838495, 963980.77503829856868833 1077802.31638198206201196))'
            ],
            '13-14': [
                'MultiLineString ((963210.47528458514716476 1077644.75307651958428323, 963255.32157539459876716 1077724.74916282831691206))'
            ],
            '5-7': [
                'MultiLineString ((964309.98692709254100919 1077617.49567248369567096, 964144.41837483353447169 1077577.06614228105172515),(964144.41837483353447169 1077577.06614228105172515, 963905.69162506482098252 1077713.75645868084393442))'
            ],
            '335-337': [
                'MultiLineString ((963643.395574557245709 1077747.43814651435241103, 963543.5341855603037402 1077760.18016819190233946))'
            ]
        }

        for pair, overlaps in line_overlaps.items():
            print("Testing pair {}...".format(pair))
            self.assertEqual(len(overlaps), len(expected_line_overlaps[pair]))
            for overlap in overlaps:
                self.assertIn(overlap, expected_line_overlaps[pair])
コード例 #21
0
 def get_connector(cls) -> DBConnector:
     return get_gpkg_conn('test_ladm_snr_gpkg')
コード例 #22
0
 def get_connector(cls) -> DBConnector:
     return get_gpkg_conn('test_ladm_integration_gpkg')
コード例 #23
0
    def test_gpkg_get_models(self):
        print("\nINFO: Validate get models method() in geopackage...")
        expected_dict = {
            'test_ladm_all_models_gpkg': [
                self.ladmcol_models.model(
                    LADMNames.VALUATION_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.CADASTRAL_CARTOGRAPHY_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SUPPLIES_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SUPPLIES_INTEGRATION_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SNR_DATA_SUPPLIES_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SURVEY_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.ISO19107_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.LADM_COL_MODEL_KEY).full_name()
            ],
            'test_ladm_integration_gpkg': [
                self.ladmcol_models.model(
                    LADMNames.SNR_DATA_SUPPLIES_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SUPPLIES_INTEGRATION_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SUPPLIES_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.ISO19107_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.LADM_COL_MODEL_KEY).full_name()
            ],
            'test_ladm_survey_model_gpkg': [
                self.ladmcol_models.model(
                    LADMNames.SURVEY_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SNR_DATA_SUPPLIES_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SUPPLIES_INTEGRATION_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.SUPPLIES_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.ISO19107_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.LADM_COL_MODEL_KEY).full_name()
            ],
            'test_ladm_cadastral_manager_data_gpkg': [
                self.ladmcol_models.model(
                    LADMNames.SUPPLIES_MODEL_KEY).full_name(),
                self.ladmcol_models.model(
                    LADMNames.ISO19107_MODEL_KEY).full_name()
            ]
        }

        for gpkg_schema_name in expected_dict:
            self.db_gpkg = get_gpkg_conn(gpkg_schema_name)
            res, code, msg = self.db_gpkg.test_connection()
            self.assertTrue(res, msg)

            model_names = self.db_gpkg.get_models()
            self.assertEqual(set(expected_dict[gpkg_schema_name]),
                             set(model_names))
 def get_connector(cls) -> DBConnector:
     return get_gpkg_conn('test_ladm_cadastral_manager_data_gpkg')
コード例 #25
0
 def get_connector(cls) -> DBConnector:
     return get_gpkg_conn('test_ladm_cadastral_cartography_gpkg')
コード例 #26
0
 def get_connector(cls) -> DBConnector:
     return get_gpkg_conn('test_ladm_valuation_model_gpkg')
コード例 #27
0
 def setUpClass(cls):
     print("INFO: Restoring databases to be used")
     restore_schema('test_ladm_cadastral_manager_data')
     cls.db_pg = get_pg_conn('test_ladm_cadastral_manager_data')
     cls.db_gpkg = get_gpkg_conn('test_ladm_cadastral_manager_data_gpkg')
コード例 #28
0
    def test_validate_topology_relation_between_point_boundary_boundary(self):
        print('\nINFO: Validating that the relation between point boundary and boundary is registered in the topology table ...')

        gpkg_path = get_test_copy_path('db/static/gpkg/quality_validations.gpkg')
        self.db_gpkg = get_gpkg_conn('tests_quality_validations_gpkg')
        names = self.db_gpkg.names
        names.T_ID_F = 't_id'  # Static label is set because the database does not have the ladm structure

        uri_boundary_points = gpkg_path + '|layername=good_boundary_points'
        uri_boundary = gpkg_path + '|layername=good_boundary'
        uri_points_ccl_table = gpkg_path + '|layername=pointsCcl'

        boundary_layer = QgsVectorLayer(uri_boundary, 'boundary_points', 'ogr')
        boundary_points_layer = QgsVectorLayer(uri_boundary_points, 'boundary', 'ogr')
        points_ccl_table = QgsVectorLayer(uri_points_ccl_table, 'pointsCcl', 'ogr')

        dic_points_ccl = dict()
        for feature_point_ccl in points_ccl_table.getFeatures():
            key = "{}-{}".format(feature_point_ccl['boundary_point_id'], feature_point_ccl['boundary_id'])
            if key in dic_points_ccl:
                dic_points_ccl[key] += 1
            else:
                dic_points_ccl.update({key:1})

        # verify that the relation between point boundary and boundary is registered in the topology table
        missing_topology = list()
        duplicates_topology = list()
        points_selected = self.geometry.join_boundary_points_with_boundary_discard_nonmatching(boundary_points_layer, boundary_layer, names.T_ID_F)

        for point_selected in points_selected:
            boundary_point_id = point_selected[names.T_ID_F]
            boundary_id = point_selected['{}_2'.format(names.T_ID_F)]
            key_query = "{}-{}".format(boundary_point_id, boundary_id)

            if key_query in dic_points_ccl:
                if dic_points_ccl[key_query] > 1:
                    duplicates_topology.append([boundary_point_id, boundary_id])
            else:
                missing_topology.append([boundary_point_id, boundary_id])

        self.assertEqual(len(missing_topology), 0)
        self.assertEqual(len(duplicates_topology), 0)

        uri_points_ccl_table = gpkg_path + '|layername=pointsCcl_bad'
        points_ccl_table = QgsVectorLayer(uri_points_ccl_table, 'pointsCcl_bad', 'ogr')

        dic_points_ccl = dict()
        for feature_point_ccl in points_ccl_table.getFeatures():
            key = "{}-{}".format(feature_point_ccl['boundary_point_id'], feature_point_ccl['boundary_id'])
            if key in dic_points_ccl:
                dic_points_ccl[key] += 1
            else:
                dic_points_ccl.update({key: 1})

        # verify that the relation between point boundary and boundary is registered in the topology table
        missing_topology = list()
        duplicates_topology = list()
        points_selected = self.geometry.join_boundary_points_with_boundary_discard_nonmatching(boundary_points_layer, boundary_layer, names.T_ID_F)

        for point_selected in points_selected:
            boundary_point_id = point_selected[names.T_ID_F]
            boundary_id = point_selected['{}_2'.format(names.T_ID_F)]
            key_query = "{}-{}".format(boundary_point_id, boundary_id)

            if key_query in dic_points_ccl:
                if dic_points_ccl[key_query] > 1: # register more that once
                    duplicates_topology.append([boundary_point_id, boundary_id])
            else: # no register
                missing_topology.append([boundary_point_id, boundary_id])

        self.assertEqual(missing_topology, [[1, 1]])
        self.assertEqual(duplicates_topology, [[20, 1]])
コード例 #29
0
 def get_connector(cls) -> DBConnector:
     return get_gpkg_conn('test_ladm_all_models_gpkg')