Ejemplo n.º 1
0
def test_multigeom_vrt():
    cfg = OgrConfig(
        ds="./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd",
        config="./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.cfg",
    )
    vrt = prettify(cfg.generate_vrt())
    expected = """<OGRVRTLayer name="oerebkrm09trsfr_transferstruktur_geometrie">
    <SrcDataSource relativeToVRT="0" shared="1">./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd</SrcDataSource>
    <SrcLayer>OeREBKRM09trsfr.Transferstruktur.Geometrie</SrcLayer>
    <Field name="publiziertab" src="publiziertAb" type="String"/>
    <Field name="metadatengeobasisdaten" src="MetadatenGeobasisdaten" type="String"/>
    <Field name="tid" src="TID" type="String"/>
    <Field name="zustaendigestelle" src="ZustaendigeStelle" type="String"/>
    <Field name="rechtsstatus" src="Rechtsstatus" type="String"/>
    <Field name="eigentumsbeschraenkung" src="Eigentumsbeschraenkung" type="String"/>
    <GeometryField field="Punkt" name="punkt">
      <GeometryType>wkbPoint</GeometryType>
      <SRS>EPSG:21781</SRS>
    </GeometryField>
    <GeometryField field="Flaeche" name="flaeche">
      <GeometryType>wkbPolygon</GeometryType>
      <SRS>EPSG:21781</SRS>
    </GeometryField>
    <GeometryField field="Linie" name="linie">
      <GeometryType>wkbMultiLineString</GeometryType>
      <SRS>EPSG:21781</SRS>
    </GeometryField>
  </OGRVRTLayer>"""
    print vrt
    assert expected in vrt
Ejemplo n.º 2
0
def test_multigeom_vrt():
    cfg = OgrConfig(
        ds=
        "./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd",
        config=
        "./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.cfg")
    vrt = prettify(cfg.generate_vrt())
    expected = """<OGRVRTLayer name="oerebkrm09trsfr_transferstruktur_geometrie">
    <SrcDataSource relativeToVRT="0" shared="1">./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,./tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd</SrcDataSource>
    <SrcLayer>OeREBKRM09trsfr.Transferstruktur.Geometrie</SrcLayer>
    <Field name="publiziertab" src="publiziertAb" type="String"/>
    <Field name="metadatengeobasisdaten" src="MetadatenGeobasisdaten" type="String"/>
    <Field name="tid" src="TID" type="String"/>
    <Field name="zustaendigestelle" src="ZustaendigeStelle" type="String"/>
    <Field name="rechtsstatus" src="Rechtsstatus" type="String"/>
    <Field name="eigentumsbeschraenkung" src="Eigentumsbeschraenkung" type="String"/>
    <GeometryField field="Punkt" name="punkt">
      <GeometryType>wkbPoint</GeometryType>
      <SRS>EPSG:21781</SRS>
    </GeometryField>
    <GeometryField field="Flaeche" name="flaeche">
      <GeometryType>wkbPolygon</GeometryType>
      <SRS>EPSG:21781</SRS>
    </GeometryField>
    <GeometryField field="Linie" name="linie">
      <GeometryType>wkbMultiLineString</GeometryType>
      <SRS>EPSG:21781</SRS>
    </GeometryField>
  </OGRVRTLayer>"""
    print vrt
    assert expected in vrt
Ejemplo n.º 3
0
def test_ili_config():
    cfg = OgrConfig(ds="./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd")
    cfgjson = cfg.generate_config(dst_format="PostgreSQL", srs=21781)
    expected = """"roadsexdm2ien_roadsextended_streetaxis": {
      "fields": {
        "tid": {
          "src": "TID", 
          "type": "String"
        }, 
        "street": {
          "src": "Street", 
          "type": "String"
        }, 
        "precision": {
          "src": "Precision", 
          "type": "String"
        }
      }, 
      "geometry_type": "MultiLineString", 
      "src_layer": "RoadsExdm2ien.RoadsExtended.StreetAxis", 
      "geom_fields": {
        "geometry": {
          "src": "Geometry", 
          "type": "MultiLineString", 
          "srs": 21781
        }
      }
    }"""
    print cfgjson
    assert expected in cfgjson
Ejemplo n.º 4
0
def test_ili_config():
    cfg = OgrConfig(
        ds="./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd")
    cfgjson = cfg.generate_config(dst_format='PostgreSQL', srs=21781)
    expected = """"roadsexdm2ien_roadsextended_streetaxis": {
      "fields": {
        "tid": {
          "src": "TID", 
          "type": "String"
        }, 
        "street": {
          "src": "Street", 
          "type": "String"
        }, 
        "precision": {
          "src": "Precision", 
          "type": "String"
        }
      }, 
      "geometry_type": "MultiLineString", 
      "src_layer": "RoadsExdm2ien.RoadsExtended.StreetAxis", 
      "geom_fields": {
        "geometry": {
          "src": "Geometry", 
          "type": "MultiLineString", 
          "srs": 21781
        }
      }
    }"""
    print cfgjson
    assert expected in cfgjson
def test_ili_to_geojson():
    # ogr genconfig --format PostgreSQL tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imd --model tests/data/ili/RoadsExdm2ien.imd --srs=EPSG:21781 >tests/data/ili/RoadsExdm2ien.cfg
    trans = OgrConfig(
        config="tests/data/ili/RoadsExdm2ien.cfg",
        ds="tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imd")
    __, dstfile = tempfile.mkstemp(suffix='.json')
    os.remove(dstfile)
    trans.transform(dstfile, "GeoJSON", layers=["streetaxis"])
    print(dstfile)
    result = codecs.open(dstfile, encoding='utf-8').read()
    expected = """{
"type": "FeatureCollection",
"name": "streetaxis",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::21781" } },
"features": [
{ "type": "Feature", "properties": { "street_id": 1, "tid": "8", "precision": "precise" }, "geometry": { "type": "LineString", "coordinates": [ [ 55.6, 37.649 ], [ 15.573, 25.785 ] ] } },
{ "type": "Feature", "properties": { "street_id": 1, "tid": "9", "precision": "precise" }, "geometry": { "type": "LineString", "coordinates": [ [ 55.6, 37.649 ], [ 94.99, 50.109 ] ] } },
{ "type": "Feature", "properties": { "street_id": 1, "tid": "10", "precision": "precise" }, "geometry": { "type": "LineString", "coordinates": [ [ 94.99, 50.109 ], [ 101.099, 52.279 ] ] } },
{ "type": "Feature", "properties": { "street_id": 1, "tid": "11", "precision": "precise" }, "geometry": { "type": "LineString", "coordinates": [ [ 101.099, 52.279 ], [ 126.1, 62.279 ] ] } },
{ "type": "Feature", "properties": { "street_id": 2, "tid": "12", "precision": "precise" }, "geometry": { "type": "LineString", "coordinates": [ [ 94.99, 50.109 ], [ 89.504, 65.795 ], [ 83.594, 75.598 ], [ 71.774, 80.712 ], [ 11.423, 91.154 ] ] } },
{ "type": "Feature", "properties": { "street_id": 3, "tid": "13", "precision": "unprecise" }, "geometry": { "type": "LineString", "coordinates": [ [ 101.099, 52.279 ], [ 107.4, 14.603 ] ] } },
{ "type": "Feature", "properties": { "street_id": 4, "tid": "15", "precision": "unprecise" }, "geometry": { "type": "LineString", "coordinates": [ [ 55.6, 37.649 ], [ 49.359, 56.752 ] ] } }
]
}
"""
    assert sorted(expected) == sorted(result)
    os.remove(dstfile)
Ejemplo n.º 6
0
 def _ogr_config(self, ds):
     ogrconfig = self.ui.mConfigLineEdit.text()
     self._log_output("_ogr_config ds: %s cfg: %s" % (ds, ogrconfig))
     if ogrconfig:
         cfg = OgrConfig(ds=ds, config=ogrconfig)
     else:
         cfg = OgrConfig(ds=ds, model=self.ui.mModelLineEdit.text())
     return cfg
Ejemplo n.º 7
0
def manualtest_ili_with_struct_to_gml():
    #ogr genconfig --format GML tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd --model tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd --srs=EPSG:21781 >tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118-gml.cfg
    trans = OgrConfig(config="tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.cfg",
                      ds="tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd")
    __, dstfile = tempfile.mkstemp(suffix='.gml')
    os.remove(dstfile)
    trans.transform(dstfile, "GML")
    print dstfile
    assert False
    os.remove(dstfile)
Ejemplo n.º 8
0
def manualtest_ili_to_spatialite():
    #ogr genconfig --format SQLite tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd --model tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd --srs=EPSG:21781 >tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.cfg
    trans = OgrConfig(config="tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.cfg",
      ds="tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd")
    __, dstfile = tempfile.mkstemp(suffix='.sqlite')
    os.remove(dstfile)
    trans.transform(dstfile, "SQLite")
    print dstfile
    result = os.popen("echo .dump | sqlite3 %s" % dstfile).read()
    assert False
    os.remove(dstfile)
Ejemplo n.º 9
0
def test_ili_to_geojson():
    #ogr genconfig --format PostgreSQL tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imd --model tests/data/ili/RoadsExdm2ien.imd --srs=EPSG:21781 >tests/data/ili/RoadsExdm2ien.cfg
    trans = OgrConfig(config="tests/data/ili/RoadsExdm2ien.cfg",
                      ds="tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imd")
    __, dstfile = tempfile.mkstemp(suffix='.json')
    os.remove(dstfile)
    trans.transform(dstfile, "GeoJSON", layers=["streetaxis"])
    print dstfile
    result = codecs.open(dstfile, encoding='utf-8').read()
    expected = """{ "type": "Feature", "properties": { "tid": "8", "precision": "precise", "street_id": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ 55.6, 37.649 ], [ 15.573, 25.785 ] ] } }"""
    assert expected in result
    os.remove(dstfile)
Ejemplo n.º 10
0
def test_ili_to_postgis():
    # ogr genconfig --format PostgreSQL tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd --model tests/data/np/NP_73_CH_de_ili2.imd --srs=EPSG:21781 >tests/data/np/NP_73_CH_de_ili2-pg.cfg
    trans = OgrConfig(
        config="tests/data/np/NP_73_CH_de_ili2-pg.cfg",
        ds="tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd")
    __, dstfile = tempfile.mkstemp(suffix='.sql')
    trans.transform(dstfile, "PGDump")
    print dstfile
    sql = codecs.open(dstfile, encoding='utf-8').read()
    assert """CREATE TABLE "public"."n0_grundnutzung_zonenflaeche" (""" in sql
    assert """SELECT AddGeometryColumn('public','n0_grundnutzung_zonenflaeche','geometrie',21781,'POLYGON',2);""" in sql
    assert """INSERT INTO "public"."n0_grundnutzung_zonenflaeche" ("geometrie" , "zonentyp_1", "herkunft", "mutation", "tid", "qualitaet") VALUES ('01030000201555000001000000550000007D3F355ECA312541FA7E6ABCDD2E0E41355EBAC9923125411904560EC72D0E41EE7C3FB5923125412DB29DEF9D2C0E4154E3A55B80312541713D0AD7472C0E41A4703DCA7731254183C0CAA11F2C0E414C37898171312541F4FDD478F92B0E414260E5506E3125413D0AD7A3022C0E413F355EFA68312541BC749318122C0E4121B072A8633125416DE7FBA9212C0E4154E3A55B5E31254193180456312C0E41D9CEF7135931254177BE9F1A412C0E414260E5D053312541D122DBF9502C0E418D976E924E3125415C8FC2F5602C0E41448B6CE74A3125411D5A643B6C2C0E419A99995949312541E9263108712C0E418941602544312541A8C64B37812C0E41CBA145F63E31254123DBF97E912C0E415EBA49CC393125415A643BDFA12C0E41448B6CA73431254108AC1C5AB22C0E417B14AE872F3125412DB29DEFC22C0E4104560E6D2A3125410E2DB29DD32C0E41DF4F8D5725312541AC1C5A64E42C0E415839B4C8073125411904560E472D0E41D122DBF9F030254117D9CEF7952D0E410AD7A3B0D83025411F85EB51EE2D0E41E5D0221BAC302541022B87169C2E0E41273108ECA7302541BE9F1A2FAD2E0E41AE47E1FAA6302541D34D6210B12E0E41E9263188A23025417F6ABC74C32E0E41C3F5281C9E3025412DB29DEFD52E0E415C8FC2B599302541DD240681E82E0E41AE47E1FA97302541E5D022DBEF2E0E41B6F3FD54953025414A0C022BFB2E0E413F355EFA90302541FED478E90D2F0E41F853E3A58C302541B4C876BE202F0E41DF4F8D57883025416DE7FBA9332F0E41F853E3E574302541560E2DB2912F0E416F1283C08930254125068195DD2F0E41F4FDD4F8963025411283C0CA0C300E411F85EB519E3025416210583928300E41CDCCCCCCB83025417F6ABC7488300E41333333B3DC302541759318040F310E41B4C8763EE6302541D122DBF9F5300E411283C0CA2A312541EC51B81E42300E41C520B0B230312541C976BE9F32300E413D0AD7633A312541D122DBF988300E41378941E0BD3125414260E5D092320E4114AE4721C2312541931804567C320E41D34D6210E5312541CBA145B6C3310E419EEFA786E6312541BC749318BC310E41986E1203E8312541F6285C8FB4310E41C1CAA185E931254177BE9F1AAD310E418716D90EEB3125413F355EBAA5310E41EC51B89EEC3125410AD7A3709E310E4110583934EE3125411D5A643B97310E41643BDFCFEF31254177BE9F1A90310E41E7FBA971F13125418D976E1289310E419A999919F3312541EC51B81E82310E410C022BC7F4312541068195437B310E41AE47E17AF63125416891ED7C74310E4110583934F83125414260E5D06D310E41C520B0F2F93125416210583967310E41A8C64BB7FB312541FA7E6ABC60310E414C378981FD312541931804565A310E41986E1283FD312541643BDF4F5A310E414260E550FF312541E926310854310E418941602501322541B6F3FDD44D310E4191ED7CFF0232254185EB51B847310E41EC51B8DE0432254185EB51B841310E41986E12C3063225418716D9CE3B310E41273108AC08322541BA490C0236310E4108AC1C9A0A322541AAF1D24D30310E413BDF4F8D0C322541105839B42A310E4152B81E850E322541EE7C3F3525310E414C378981103225414260E5D01F310E41BA490C8212322541C74B37891A310E417B14AE8714322541C3F5285C15310E41B072689116322541F0A7C64B10310E415A643B9F18322541931804560B310E41E7FBA9B11A3225416891ED7C06310E415C8FC2B51A322541C520B07206310E417B14AEC72F322541A8C64B37DA300E41759318C43832254196438B6CCB300E41F0A7C60B2D3225417593180497300E417D3F355ECA312541FA7E6ABCDD2E0E41', 'xz4e43cb2800000014', 'Aufnahme', 'xz4e43d386e7880000', 'xz4e43d63ce7880007', 'AV93');""" in sql
    os.remove(dstfile)
Ejemplo n.º 11
0
def test_ili_to_postgis():
    # ogr genconfig --format PostgreSQL tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd --model tests/data/np/NP_73_CH_de_ili2.imd --srs=EPSG:21781 >tests/data/np/NP_73_CH_de_ili2-pg.cfg
    trans = OgrConfig(
        config="tests/data/np/NP_73_CH_de_ili2-pg.cfg",
        ds="tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd")
    __, dstfile = tempfile.mkstemp(suffix='.sql')
    trans.transform(dstfile, "PGDump")
    print dstfile
    sql = codecs.open(dstfile, encoding='utf-8').read()
    assert """CREATE TABLE "public"."n0_grundnutzung_zonenflaeche" (""" in sql
    assert """SELECT AddGeometryColumn('public','n0_grundnutzung_zonenflaeche','geometrie',21781,'POLYGON',2);""" in sql
    assert """INSERT INTO "public"."n0_grundnutzung_zonenflaeche" ("geometrie" , "zonentyp_1", "herkunft", "mutation", "tid", "qualitaet") VALUES ('01030000201555000001000000550000007D3F355ECA312541FA7E6ABCDD2E0E41355EBAC9923125411904560EC72D0E41EE7C3FB5923125412DB29DEF9D2C0E4154E3A55B80312541713D0AD7472C0E41A4703DCA7731254183C0CAA11F2C0E414C37898171312541F4FDD478F92B0E414260E5506E3125413D0AD7A3022C0E413F355EFA68312541BC749318122C0E4121B072A8633125416DE7FBA9212C0E4154E3A55B5E31254193180456312C0E41D9CEF7135931254177BE9F1A412C0E414260E5D053312541D122DBF9502C0E418D976E924E3125415C8FC2F5602C0E41448B6CE74A3125411D5A643B6C2C0E419A99995949312541E9263108712C0E418941602544312541A8C64B37812C0E41CBA145F63E31254123DBF97E912C0E415EBA49CC393125415A643BDFA12C0E41448B6CA73431254108AC1C5AB22C0E417B14AE872F3125412DB29DEFC22C0E4104560E6D2A3125410E2DB29DD32C0E41DF4F8D5725312541AC1C5A64E42C0E415839B4C8073125411904560E472D0E41D122DBF9F030254117D9CEF7952D0E410AD7A3B0D83025411F85EB51EE2D0E41E5D0221BAC302541022B87169C2E0E41273108ECA7302541BE9F1A2FAD2E0E41AE47E1FAA6302541D34D6210B12E0E41E9263188A23025417F6ABC74C32E0E41C3F5281C9E3025412DB29DEFD52E0E415C8FC2B599302541DD240681E82E0E41AE47E1FA97302541E5D022DBEF2E0E41B6F3FD54953025414A0C022BFB2E0E413F355EFA90302541FED478E90D2F0E41F853E3A58C302541B4C876BE202F0E41DF4F8D57883025416DE7FBA9332F0E41F853E3E574302541560E2DB2912F0E416F1283C08930254125068195DD2F0E41F4FDD4F8963025411283C0CA0C300E411F85EB519E3025416210583928300E41CDCCCCCCB83025417F6ABC7488300E41333333B3DC302541759318040F310E41B4C8763EE6302541D122DBF9F5300E411283C0CA2A312541EC51B81E42300E41C520B0B230312541C976BE9F32300E413D0AD7633A312541D122DBF988300E41378941E0BD3125414260E5D092320E4114AE4721C2312541931804567C320E41D34D6210E5312541CBA145B6C3310E419EEFA786E6312541BC749318BC310E41986E1203E8312541F6285C8FB4310E41C1CAA185E931254177BE9F1AAD310E418716D90EEB3125413F355EBAA5310E41EC51B89EEC3125410AD7A3709E310E4110583934EE3125411D5A643B97310E41643BDFCFEF31254177BE9F1A90310E41E7FBA971F13125418D976E1289310E419A999919F3312541EC51B81E82310E410C022BC7F4312541068195437B310E41AE47E17AF63125416891ED7C74310E4110583934F83125414260E5D06D310E41C520B0F2F93125416210583967310E41A8C64BB7FB312541FA7E6ABC60310E414C378981FD312541931804565A310E41986E1283FD312541643BDF4F5A310E414260E550FF312541E926310854310E418941602501322541B6F3FDD44D310E4191ED7CFF0232254185EB51B847310E41EC51B8DE0432254185EB51B841310E41986E12C3063225418716D9CE3B310E41273108AC08322541BA490C0236310E4108AC1C9A0A322541AAF1D24D30310E413BDF4F8D0C322541105839B42A310E4152B81E850E322541EE7C3F3525310E414C378981103225414260E5D01F310E41BA490C8212322541C74B37891A310E417B14AE8714322541C3F5285C15310E41B072689116322541F0A7C64B10310E415A643B9F18322541931804560B310E41E7FBA9B11A3225416891ED7C06310E415C8FC2B51A322541C520B07206310E417B14AEC72F322541A8C64B37DA300E41759318C43832254196438B6CCB300E41F0A7C60B2D3225417593180497300E417D3F355ECA312541FA7E6ABCDD2E0E41', 'xz4e43cb2800000014', 'Aufnahme', 'xz4e43d386e7880000', 'xz4e43d63ce7880007', 'AV93');""" in sql
    os.remove(dstfile)
def test_ili_schema_to_postgis():
    imd = ImdParser("./tests/data/np/NP_73_CH_de_ili2.imd")
    transferfn = imd.gen_empty_transfer_file()
    trans = OgrConfig(config="tests/data/np/NP_73_CH_de_ili2-pg.cfg",
                      ds=transferfn + ",tests/data/np/NP_73_CH_de_ili2.imd")
    __, dstfile = tempfile.mkstemp(suffix='.sql')
    trans.transform(dstfile, "PGDump")
    print(dstfile)
    sql = codecs.open(dstfile, encoding='utf-8').read()
    assert """CREATE TABLE "public"."n0_grundnutzung_zonenflaeche" (""" in sql
    assert """SELECT AddGeometryColumn('public','n0_grundnutzung_zonenflaeche','geometrie',21781,'POLYGON',2);""" in sql
    os.remove(transferfn)
    os.remove(dstfile)
Ejemplo n.º 13
0
def test_ili_to_geojson():
    #ogr genconfig --format PostgreSQL tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imd --model tests/data/ili/RoadsExdm2ien.imd --srs=EPSG:21781 >tests/data/ili/RoadsExdm2ien.cfg
    trans = OgrConfig(
        config="tests/data/ili/RoadsExdm2ien.cfg",
        ds="tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imd")
    __, dstfile = tempfile.mkstemp(suffix='.json')
    os.remove(dstfile)
    trans.transform(dstfile, "GeoJSON", layers=["streetaxis"])
    print dstfile
    result = codecs.open(dstfile, encoding='utf-8').read()
    expected = """{ "type": "Feature", "properties": { "tid": "8", "precision": "precise", "street_id": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ 55.6, 37.649 ], [ 15.573, 25.785 ] ] } }"""
    assert expected in result
    os.remove(dstfile)
Ejemplo n.º 14
0
def test_ili_schema_to_postgis():
    imd = ImdParser("./tests/data/np/NP_73_CH_de_ili2.imd")
    transferfn = imd.gen_empty_transfer_file()
    trans = OgrConfig(
        config="tests/data/np/NP_73_CH_de_ili2-pg.cfg",
        ds=transferfn+",tests/data/np/NP_73_CH_de_ili2.imd")
    __, dstfile = tempfile.mkstemp(suffix='.sql')
    trans.transform(dstfile, "PGDump")
    print dstfile
    sql = codecs.open(dstfile, encoding='utf-8').read()
    assert """CREATE TABLE "public"."n0_grundnutzung_zonenflaeche" (""" in sql
    assert """SELECT AddGeometryColumn('public','n0_grundnutzung_zonenflaeche','geometrie',21781,'POLYGON',2);""" in sql
    os.remove(transferfn)
    os.remove(dstfile)
def test_encoding():
    # ogr genconfig --format GML tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd --model tests/data/np/NP_73_CH_de_ili2.imd --srs=EPSG:21781 >tests/data/np/NP_73_CH_de_ili2.cfg
    trans = OgrConfig(
        config="tests/data/np/NP_73_CH_de_ili2.cfg",
        ds="tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd")
    __, dstfile = tempfile.mkstemp(suffix='.gml')
    os.remove(dstfile)
    trans.transform(dstfile, "GML")
    print(dstfile)
    gml = codecs.open(dstfile, encoding='utf-8').read()
    assert u"Bundesgesetz über die Raumplanung" in gml
    os.remove(dstfile)

    trans = OgrConfig(
        config="tests/data/np/NP_73_CH_de_ili2.cfg",
        ds=
        "tests/data/np/NP_Example_latin1.xtf,tests/data/np/NP_73_CH_de_ili2.imd"
    )
    # NP_Example_latin1.xtf has latin1 header and contains entities like &#xfc; as ü
    __, dstfile = tempfile.mkstemp(suffix='.gml')
    os.remove(dstfile)
    trans.transform(dstfile, "GML")
    print(dstfile)
    gml = codecs.open(dstfile, encoding='utf-8').read()
    assert u"Bundesgesetz über die Raumplanung" not in gml
    os.remove(dstfile)
def manualtest_ili_with_struct_to_gml():
    # ogr genconfig --format GML tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd --model tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd --srs=EPSG:21781 >tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118-gml.cfg
    trans = OgrConfig(
        config=
        "tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.cfg",
        ds=
        "tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd"
    )
    __, dstfile = tempfile.mkstemp(suffix='.gml')
    os.remove(dstfile)
    trans.transform(dstfile, "GML")
    print(dstfile)
    assert False
    os.remove(dstfile)
Ejemplo n.º 17
0
def test_reverse_vrt():
    cfg = OgrConfig(ds="./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd",
                    config="./tests/data/ili/RoadsExdm2ien.cfg")
    vrt = prettify(cfg.generate_reverse_vrt())
    expected = """<OGRVRTLayer name="RoadsExdm2ien.RoadsExtended.RoadSign">
    <SrcDataSource relativeToVRT="0" shared="1">./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd</SrcDataSource>
    <SrcLayer>roadsign</SrcLayer>
    <Field name="TID" src="tid"/>
    <Field name="Type" src="type"/>
    <GeometryField field="position" name="Position">
      <GeometryType>wkbPoint</GeometryType>
    </GeometryField>
  </OGRVRTLayer>"""
    print vrt
    assert expected in vrt
Ejemplo n.º 18
0
def test_shape_config():
    cfg = OgrConfig(ds="tests/data/osm/railway.shp")
    cfgjson = cfg.generate_config(dst_format="PostgreSQL")
    expected = """{
  "//": "OGR transformation configuration", 
  "dst_dsco": {}, 
  "dst_lco": {
    "SCHEMA": "public"
  }, 
  "layers": {
    "railway": {
      "fields": {
        "keyvalue": {
          "src": "keyvalue", 
          "type": "String", 
          "width": 80
        }, 
        "lastchange": {
          "src": "lastchange", 
          "type": "Date", 
          "width": 10
        }, 
        "type": {
          "src": "type", 
          "type": "String", 
          "width": 255
        }, 
        "name": {
          "src": "name", 
          "type": "String", 
          "width": 255
        }, 
        "osm_id": {
          "src": "osm_id", 
          "type": "Real", 
          "width": 11
        }
      }, 
      "geometry_type": "LineString", 
      "src_layer": "railway", 
      "geom_fields": {}
    }
  }, 
  "src_format": "ESRI Shapefile", 
  "dst_format": "PostgreSQL"
}"""
    print cfgjson
    assert cfgjson == expected
Ejemplo n.º 19
0
def test_shape_config():
    cfg = OgrConfig(ds="tests/data/osm/railway.shp")
    cfgjson = cfg.generate_config(dst_format='PostgreSQL')
    expected = """{
  "//": "OGR transformation configuration", 
  "dst_dsco": {}, 
  "dst_lco": {
    "SCHEMA": "public"
  }, 
  "layers": {
    "railway": {
      "fields": {
        "keyvalue": {
          "src": "keyvalue", 
          "type": "String", 
          "width": 80
        }, 
        "lastchange": {
          "src": "lastchange", 
          "type": "Date", 
          "width": 10
        }, 
        "type": {
          "src": "type", 
          "type": "String", 
          "width": 255
        }, 
        "name": {
          "src": "name", 
          "type": "String", 
          "width": 255
        }, 
        "osm_id": {
          "src": "osm_id", 
          "type": "Real", 
          "width": 11
        }
      }, 
      "geometry_type": "LineString", 
      "src_layer": "railway", 
      "geom_fields": {}
    }
  }, 
  "src_format": "ESRI Shapefile", 
  "dst_format": "PostgreSQL"
}"""
    print cfgjson
    assert cfgjson == expected
Ejemplo n.º 20
0
def test_reverse_vrt():
    cfg = OgrConfig(
        ds="./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd",
        config="./tests/data/ili/RoadsExdm2ien.cfg")
    vrt = prettify(cfg.generate_reverse_vrt())
    expected = """<OGRVRTLayer name="RoadsExdm2ien.RoadsExtended.RoadSign">
    <SrcDataSource relativeToVRT="0" shared="1">./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd</SrcDataSource>
    <SrcLayer>roadsign</SrcLayer>
    <Field name="TID" src="tid"/>
    <Field name="Type" src="type"/>
    <GeometryField field="position" name="Position">
      <GeometryType>wkbPoint</GeometryType>
    </GeometryField>
  </OGRVRTLayer>"""
    print vrt
    assert expected in vrt
def manualtest_ili_to_spatialite():
    # ogr genconfig --format SQLite tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd --model tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd --srs=EPSG:21781 >tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.cfg
    trans = OgrConfig(
        config=
        "tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.cfg",
        ds=
        "tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.xtf,tests/data/ch.bazl/ch.bazl.sicherheitszonenplan.oereb_20131118.imd"
    )
    __, dstfile = tempfile.mkstemp(suffix='.sqlite')
    os.remove(dstfile)
    # Takes more than 2'
    trans.transform(dstfile, "SQLite")
    print(dstfile)
    result = os.popen("echo .dump | sqlite3 %s" % dstfile).read()
    assert False
    os.remove(dstfile)
Ejemplo n.º 22
0
def test_np():
    cfg = OgrConfig(
        ds="tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd", model="tests/data/np/NP_73_CH_de_ili2.imd"
    )
    cfgjson = cfg.generate_config(dst_format="PostgreSQL")
    expected = """"n0_grundnutzung_zonenflaeche": {
      "fields": {
        "zonentyp_1": {
          "src": "Zonentyp_1", 
          "type": "String"
        }, 
        "herkunft": {
          "src": "Herkunft", 
          "type": "String"
        }, 
        "mutation": {
          "src": "Mutation", 
          "type": "String"
        }, 
        "tid": {
          "src": "TID", 
          "type": "String"
        }, 
        "qualitaet": {
          "src": "Qualitaet", 
          "type": "String"
        }, 
        "bemerkungen": {
          "src": "Bemerkungen", 
          "type": "String"
        }
      }, 
      "geometry_type": "Polygon", 
      "src_layer": "Nutzungsplanung.Nutzungsplanung.Grundnutzung_Zonenflaeche", 
      "geom_fields": {
        "geometrie": {
          "src": "Geometrie", 
          "type": "Polygon"
        }
      }
    }"""
    print cfgjson
    assert expected in cfgjson
Ejemplo n.º 23
0
def test_ili_to_gml():
    trans = OgrConfig(
        config="tests/data/np/NP_73_CH_de_ili2.cfg",
        ds="tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd")
    __, dstfile = tempfile.mkstemp(suffix='.gml')
    os.remove(dstfile)
    trans.transform(dstfile, "GML")
    print dstfile
    gml = codecs.open(dstfile, encoding='utf-8').read()

    # GML -> XTF
    __, xtffile = tempfile.mkstemp(suffix='.xtf')
    trans.transform_reverse(xtffile + ",tests/data/np/NP_73_CH_de_ili2.imd")
    print xtffile
    xtf = codecs.open(xtffile, encoding='utf-8').read()
    zonentyp_kt = """<Nutzungsplanung.Nutzungsplanung.Grundnutzung_Zonentyp_Kt TID="xz4e43cb280000000a">
<Identifikator>142</Identifikator>
<Zonentyp_Kt>Kernzone</Zonentyp_Kt>
<Abkuerzung>K</Abkuerzung>
<Bemerkungen>Kernzone</Bemerkungen>
<Hauptnutzung_CH>Bauzonen_1.Zentrumszonen_14</Hauptnutzung_CH>
<Zonentyp_SIA>Zentrumszonen_14.Kernzone_142</Zonentyp_SIA>
</Nutzungsplanung.Nutzungsplanung.Grundnutzung_Zonentyp_Kt>"""
    assert zonentyp_kt in xtf
    assert "<COORD><C1>694511.547</C1><C2>247816.271</C2></COORD>" in xtf
    geometry_type = """<Geometrie>
<SURFACE>
<BOUNDARY>
<POLYLINE>
<COORD>"""
    assert geometry_type in xtf

    # XTF -> GML
    trans2 = OgrConfig(config="tests/data/np/NP_73_CH_de_ili2.cfg",
                       ds=xtffile + ",tests/data/np/NP_73_CH_de_ili2.imd")
    __, gmlfile2 = tempfile.mkstemp(suffix='.gml')
    trans.transform(gmlfile2, "GML")
    print gmlfile2
    gml2 = codecs.open(gmlfile2, encoding='utf-8').read()

    gml = re.sub(r'tmp.+.xsd', 'tmpXXX.xsd', gml, count=1)
    gml2 = re.sub(r'tmp.+.xsd', 'tmpXXX.xsd', gml2, count=1)
    assert gml == gml2

    # cleanup
    os.remove(dstfile)
    os.remove(xtffile)
    os.remove(gmlfile2)
Ejemplo n.º 24
0
def test_np():
    cfg = OgrConfig(
        ds="tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd",
        model="tests/data/np/NP_73_CH_de_ili2.imd")
    cfgjson = cfg.generate_config(dst_format='PostgreSQL')
    expected = """"n0_grundnutzung_zonenflaeche": {
      "fields": {
        "zonentyp_1": {
          "src": "Zonentyp_1", 
          "type": "String"
        }, 
        "herkunft": {
          "src": "Herkunft", 
          "type": "String"
        }, 
        "mutation": {
          "src": "Mutation", 
          "type": "String"
        }, 
        "tid": {
          "src": "TID", 
          "type": "String"
        }, 
        "qualitaet": {
          "src": "Qualitaet", 
          "type": "String"
        }, 
        "bemerkungen": {
          "src": "Bemerkungen", 
          "type": "String"
        }
      }, 
      "geometry_type": "Polygon", 
      "src_layer": "Nutzungsplanung.Nutzungsplanung.Grundnutzung_Zonenflaeche", 
      "geom_fields": {
        "geometrie": {
          "src": "Geometrie", 
          "type": "Polygon"
        }
      }
    }"""
    print cfgjson
    assert expected in cfgjson
Ejemplo n.º 25
0
 def on_mCreateCfgButton_clicked(self):
     outfile = QFileDialog.getSaveFileName(
         None, "Save File", self.ui.mIliLineEdit.text(),
         "OGR config (*.cfg *.CFG *.json *.JSON)")
     if not outfile:
         return
     cfg = OgrConfig(ds=self._empty_transfer_ds(),
                     model=self.ui.mModelLineEdit.text())
     self._gen_ogr_config(cfg, outfile)
     self.ui.mConfigLineEdit.setText(outfile)
     self.ui.mCfgGroupBox.setCollapsed(self.ui.mConfigLineEdit.text() == "")
def test_shape_to_geojson():
    # ogr genconfig --format PostgreSQL tests/data/osm/railway.shp >tests/data/osm/railway.cfg
    trans = OgrConfig(config="tests/data/osm/railway.cfg",
                      ds="tests/data/osm/railway.shp")
    __, dstfile = tempfile.mkstemp(suffix='.json')
    os.remove(dstfile)
    trans.transform(dstfile, "GeoJSON")
    print(dstfile)
    result = codecs.open(dstfile, encoding='utf-8').read()
    # Default import
    assert '{ "type": "rail"' not in result
    # Mapping from config
    assert '"osm_type": "rail"' in result
    geojsonstart = """{
"type": "FeatureCollection",
"name": "railways",
"crs": { "type": "name", "properties": {"""
    assert geojsonstart in result
    expected = {
        'geometry': {
            'type':
            'LineString',
            'coordinates': [[9.607321, 47.243618], [9.606866, 47.24333],
                            [9.606458, 47.24304], [9.605599, 47.24239],
                            [9.604964, 47.241844], [9.604479, 47.241367],
                            [9.604155, 47.241047], [9.603565, 47.240444],
                            [9.603248, 47.24009], [9.603007, 47.23979],
                            [9.602733, 47.23939]]
        },
        'properties': {
            'keyvalue':
            '"usage"=>"main", "railway"=>"rail", "service"=>"siding", "operator"=>"Ã\x96BB", "el',
            'changed_at': '2009/08/15',
            'osm_type': 'rail',
            'osm_id': 9440158.0
        },
        'type': 'Feature'
    }

    assert json.loads(result)['features'][0] == expected
    os.remove(dstfile)
Ejemplo n.º 27
0
def test_shape_to_geojson():
    #ogr genconfig --format PostgreSQL tests/data/osm/railway.shp >tests/data/osm/railway.cfg
    trans = OgrConfig(config="tests/data/osm/railway.cfg", ds="tests/data/osm/railway.shp")
    __, dstfile = tempfile.mkstemp(suffix='.json')
    os.remove(dstfile)
    trans.transform(dstfile, "GeoJSON")
    print dstfile
    result = codecs.open(dstfile, encoding='utf-8').read()
    #Default import
    assert '{ "type": "rail"' not in result
    #Mapping from config
    assert '{ "osm_type": "rail"' in result
    geojsonstart = """{
"type": "FeatureCollection",
                                                                                
"features": [
{ "type": "Feature", "properties": {"""
    assert geojsonstart in result
    expected = """osm_id": 35324774.000000 }, "geometry": { "type": "LineString", "coordinates": [ [ 9.542907, 47.20156 ], [ 9.542616, 47.201195 ]"""
    assert expected in result
    os.remove(dstfile)
Ejemplo n.º 28
0
def test_enums():
    cfg = OgrConfig(ds="./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd",
                    model="./tests/data/ili/RoadsExdm2ien.imd")
    cfgjson = cfg.generate_config(dst_format='PostgreSQL')
    expected = """_lart": {
      "src_name": "RoadsExdm2ben.Roads.LAttrs.LArt", 
      "values": [
        {
          "enumtxt": "welldefined", 
          "enum": "welldefined", 
          "id": 0
        }, 
        {
          "enumtxt": "fuzzy", 
          "enum": "fuzzy", 
          "id": 1
        }
      ]
    }"""
    print cfgjson
    assert expected in cfgjson
Ejemplo n.º 29
0
def test_enums():
    cfg = OgrConfig(
        ds="./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd",
        model="./tests/data/ili/RoadsExdm2ien.imd")
    cfgjson = cfg.generate_config(dst_format='PostgreSQL')
    expected = """_lart": {
      "src_name": "RoadsExdm2ben.Roads.LAttrs.LArt", 
      "values": [
        {
          "enumtxt": "welldefined", 
          "enum": "welldefined", 
          "id": 0
        }, 
        {
          "enumtxt": "fuzzy", 
          "enum": "fuzzy", 
          "id": 1
        }
      ]
    }"""
    print cfgjson
    assert expected in cfgjson
Ejemplo n.º 30
0
def test_shape_to_geojson():
    #ogr genconfig --format PostgreSQL tests/data/osm/railway.shp >tests/data/osm/railway.cfg
    trans = OgrConfig(config="tests/data/osm/railway.cfg",
                      ds="tests/data/osm/railway.shp")
    __, dstfile = tempfile.mkstemp(suffix='.json')
    os.remove(dstfile)
    trans.transform(dstfile, "GeoJSON")
    print dstfile
    result = codecs.open(dstfile, encoding='utf-8').read()
    #Default import
    assert '{ "type": "rail"' not in result
    #Mapping from config
    assert '{ "osm_type": "rail"' in result
    geojsonstart = """{
"type": "FeatureCollection",
                                                                                
"features": [
{ "type": "Feature", "properties": {"""
    assert geojsonstart in result
    expected = """osm_id": 35324774.000000 }, "geometry": { "type": "LineString", "coordinates": [ [ 9.542907, 47.20156 ], [ 9.542616, 47.201195 ]"""
    assert expected in result
    os.remove(dstfile)
Ejemplo n.º 31
0
def test_geojson_reverse_to_ili():
    #ogr transform --format GeoJSON --config tests/data/ili/RoadsExdm2ien.cfg tests/data/ili/RoadsExdm2ien_streetaxis.json tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imd streetaxis
    trans = OgrConfig(config="tests/data/ili/RoadsExdm2ien.cfg",
                      ds="tests/data/ili/RoadsExdm2ien_streetaxis.json")
    __, dstfile = tempfile.mkstemp(suffix='.xtf')
    #os.remove(dstfile)
    trans.transform_reverse(dstfile + ",tests/data/ili/RoadsExdm2ien.imd",
                            layers=["RoadsExdm2ien.RoadsExtended.StreetAxis"])
    print dstfile
    result = codecs.open(dstfile, encoding='utf-8').read()
    expected = """<DATASECTION>
<RoadsExdm2ien.RoadsExtended BID="RoadsExdm2ien.RoadsExtended">
<RoadsExdm2ien.RoadsExtended.StreetAxis TID="8">
<Geometry>
<POLYLINE>
<COORD><C1>55.6</C1><C2>37.649</C2></COORD>
<COORD><C1>15.573</C1><C2>25.785</C2></COORD>
</POLYLINE>
</Geometry>
<Street>1</Street>
<Precision>precise</Precision>
</RoadsExdm2ien.RoadsExtended.StreetAxis>"""
    assert expected in result
    os.remove(dstfile)
Ejemplo n.º 32
0
def test_geojson_reverse_to_ili():
    #ogr transform --format GeoJSON --config tests/data/ili/RoadsExdm2ien.cfg tests/data/ili/RoadsExdm2ien_streetaxis.json tests/data/ili/roads23.xtf,tests/data/ili/RoadsExdm2ien.imd streetaxis
    trans = OgrConfig(config="tests/data/ili/RoadsExdm2ien.cfg",
                      ds="tests/data/ili/RoadsExdm2ien_streetaxis.json")
    __, dstfile = tempfile.mkstemp(suffix='.xtf')
    #os.remove(dstfile)
    trans.transform_reverse(dstfile + ",tests/data/ili/RoadsExdm2ien.imd",
                            layers=["RoadsExdm2ien.RoadsExtended.StreetAxis"])
    print dstfile
    result = codecs.open(dstfile, encoding='utf-8').read()
    expected = """<DATASECTION>
<RoadsExdm2ien.RoadsExtended BID="RoadsExdm2ien.RoadsExtended">
<RoadsExdm2ien.RoadsExtended.StreetAxis TID="8">
<Geometry>
<POLYLINE>
<COORD><C1>55.6</C1><C2>37.649</C2></COORD>
<COORD><C1>15.573</C1><C2>25.785</C2></COORD>
</POLYLINE>
</Geometry>
<Street>1</Street>
<Precision>precise</Precision>
</RoadsExdm2ien.RoadsExtended.StreetAxis>"""
    assert expected in result
    os.remove(dstfile)
Ejemplo n.º 33
0
def test_ili_to_gml():
    trans = OgrConfig(
        config="tests/data/np/NP_73_CH_de_ili2.cfg",
        ds="tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd")
    __, dstfile = tempfile.mkstemp(suffix='.gml')
    os.remove(dstfile)
    trans.transform(dstfile, "GML")
    print dstfile
    gml = codecs.open(dstfile, encoding='utf-8').read()

    # GML -> XTF
    __, xtffile = tempfile.mkstemp(suffix='.xtf')
    trans.transform_reverse(xtffile + ",tests/data/np/NP_73_CH_de_ili2.imd")
    print xtffile
    xtf = codecs.open(xtffile, encoding='utf-8').read()
    zonentyp_kt = """<Nutzungsplanung.Nutzungsplanung.Grundnutzung_Zonentyp_Kt TID="xz4e43cb280000000a">
<Identifikator>142</Identifikator>
<Zonentyp_Kt>Kernzone</Zonentyp_Kt>
<Abkuerzung>K</Abkuerzung>
<Bemerkungen>Kernzone</Bemerkungen>
<Hauptnutzung_CH>Bauzonen_1.Zentrumszonen_14</Hauptnutzung_CH>
<Zonentyp_SIA>Zentrumszonen_14.Kernzone_142</Zonentyp_SIA>
</Nutzungsplanung.Nutzungsplanung.Grundnutzung_Zonentyp_Kt>"""
    assert zonentyp_kt in xtf
    assert "<COORD><C1>694511.547</C1><C2>247816.271</C2></COORD>" in xtf
    geometry_type = """<Geometrie>
<SURFACE>
<BOUNDARY>
<POLYLINE>
<COORD>"""
    assert geometry_type in xtf

    # XTF -> GML
    option = gdal.GetConfigOption('OGR_STROKE_CURVE')
    gdal.SetConfigOption('OGR_STROKE_CURVE', 'True')
    trans2 = OgrConfig(config="tests/data/np/NP_73_CH_de_ili2.cfg",
                       ds=xtffile + ",tests/data/np/NP_73_CH_de_ili2.imd")
    __, gmlfile2 = tempfile.mkstemp(suffix='.gml')
    trans.transform(gmlfile2, "GML")
    print gmlfile2
    gml2 = codecs.open(gmlfile2, encoding='utf-8').read()

    gml = re.sub(r'tmp.+.xsd', 'tmpXXX.xsd', gml, count=1)
    gml2 = re.sub(r'tmp.+.xsd', 'tmpXXX.xsd', gml2, count=1)
    assert gml == gml2

    # cleanup
    os.remove(dstfile)
    os.remove(xtffile)
    os.remove(gmlfile2)
    gdal.SetConfigOption('OGR_STROKE_CURVE', option)
Ejemplo n.º 34
0
def transform(args):
    if args.debug:
        os.environ["CPL_DEBUG"] = "on"
    trans = OgrConfig(config=args.config, ds=args.source)
    if args.reverse:
        trans.transform_reverse(args.dest, args.format,
                                layers=args.layers, debug=args.debug)
    else:
        trans.transform(args.dest, args.format,
                        layers=args.layers, debug=args.debug)
    return 0
Ejemplo n.º 35
0
def test_encoding():
    #ogr genconfig --format GML tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd --model tests/data/np/NP_73_CH_de_ili2.imd --srs=EPSG:21781 >tests/data/np/NP_73_CH_de_ili2.cfg
    trans = OgrConfig(config="tests/data/np/NP_73_CH_de_ili2.cfg",
                      ds="tests/data/np/NP_Example.xtf,tests/data/np/NP_73_CH_de_ili2.imd")
    __, dstfile = tempfile.mkstemp(suffix='.gml')
    os.remove(dstfile)
    trans.transform(dstfile, "GML")
    print dstfile
    gml = codecs.open(dstfile, encoding='utf-8').read()
    assert u"Bundesgesetz über die Raumplanung" in gml
    os.remove(dstfile)

    trans = OgrConfig(config="tests/data/np/NP_73_CH_de_ili2.cfg",
                      ds="tests/data/np/NP_Example_latin1.xtf,tests/data/np/NP_73_CH_de_ili2.imd")
    #NP_Example_latin1.xtf has latin1 header and contains entities like &#xfc; as ü
    __, dstfile = tempfile.mkstemp(suffix='.gml')
    os.remove(dstfile)
    trans.transform(dstfile, "GML")
    print dstfile
    gml = codecs.open(dstfile, encoding='utf-8').read()
    assert u"Bundesgesetz über die Raumplanung" not in gml
    os.remove(dstfile)
Ejemplo n.º 36
0
def test_layer_info():
    cfg = OgrConfig(
        ds="./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd",
        model="./tests/data/ili/RoadsExdm2ien.imd")
    assert not cfg.is_loaded()
    assert cfg.layer_names() == []
    assert cfg.enum_names() == []
    assert cfg.layer_infos() == []
    assert cfg.enum_infos() == []

    cfg.generate_config(dst_format='PostgreSQL')
    assert cfg.is_loaded()
    print cfg.layer_names()
    assert "roadsexdm2ien_roadsextended_roadsign" in cfg.layer_names()
    print cfg.enum_names()
    assert "_type" in str(cfg.enum_names())

    print cfg.layer_infos()
    print cfg.enum_infos()
    assert {
        'name': 'roadsexdm2ien_roadsextended_roadsign',
        'geom_field': 'position'
    } in cfg.layer_infos()
    assert {'name': 'roadsexdm2ben_roads_lattrs'} in cfg.layer_infos()
    assert '_precision' in str(cfg.enum_infos())
Ejemplo n.º 37
0
def genconfig(args):
    trans = OgrConfig(ds=args.source, model=args.model)
    print trans.generate_config(args.format,
                                layer_list=args.layers,
                                srs=args.srs)
    return 0
Ejemplo n.º 38
0
def write_enums(args):
    if args.debug:
        os.environ["CPL_DEBUG"] = "on"
    trans = OgrConfig(config=args.config)
    print trans.write_enum_tables(args.dest, args.format, args.debug)
    return 0
Ejemplo n.º 39
0
def test_layer_info():
    cfg = OgrConfig(
        ds="./tests/data/ili/roads23.xtf,./tests/data/ili/RoadsExdm2ien.imd", model="./tests/data/ili/RoadsExdm2ien.imd"
    )
    assert not cfg.is_loaded()
    assert cfg.layer_names() == []
    assert cfg.enum_names() == []
    assert cfg.layer_infos() == []
    assert cfg.enum_infos() == []

    cfg.generate_config(dst_format="PostgreSQL")
    assert cfg.is_loaded()
    print cfg.layer_names()
    assert "roadsexdm2ien_roadsextended_roadsign" in cfg.layer_names()
    print cfg.enum_names()
    assert "_type" in str(cfg.enum_names())

    print cfg.layer_infos()
    print cfg.enum_infos()
    assert {"name": "roadsexdm2ien_roadsextended_roadsign", "geom_field": "position"} in cfg.layer_infos()
    assert {"name": "roadsexdm2ben_roads_lattrs"} in cfg.layer_infos()
    assert "_precision" in str(cfg.enum_infos())