def ogr_gft_init(): ogrtest.gft_drv = None try: ogrtest.gft_drv = ogr.GetDriverByName("GFT") except: pass if ogrtest.gft_drv is None: return "skip" if gdaltest.gdalurlopen("http://www.google.com") is None: print("cannot open http://www.google.com") ogrtest.gft_drv = None return "skip" # Authentication keys are invalidated after a few days, so instead of modifying this # file each time, I will try to update the key regularly on the below site instead. handle = gdaltest.gdalurlopen("http://even.rouault.free.fr/ogr_gft_auth_key.txt") if handle is None: print("cannot retrieve authentication key. only read-only test are possibles") ogrtest.gft_auth_key = None else: ogrtest.gft_auth_key = handle.read() from sys import version_info if version_info >= (3, 0, 0): ogrtest.gft_auth_key = str(ogrtest.gft_auth_key, "ascii") if ogrtest.gft_auth_key[-1] == "\n": ogrtest.gft_auth_key = ogrtest.gft_auth_key[0:-1] return "success"
def check_availability(url): # Sandbox cleans at 1:05 on monday (UTC) now = datetime.utcnow() if now.weekday() == 0: if now.hour >= 1 and now.hour < 3: return False version_url = url + '/api/component/pyramid/pkg_version' if gdaltest.gdalurlopen(version_url) is None: return False # Check quota quota_url = url + '/api/resource/quota' quota_conn = gdaltest.gdalurlopen(quota_url) try: quota_json = json.loads(quota_conn.read()) quota_conn.close() if quota_json is None: return False limit = quota_json['limit'] count = quota_json['count'] return limit - count > 10 except: return False
def test_wms_12(): if gdaltest.wms_drv is None: pytest.skip() if gdaltest.metacarta_tms is not True: pytest.skip() name = "http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/" ds = gdal.Open(name) if ds is None: if gdaltest.gdalurlopen('http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/basic/0/0/0.png') is None: pytest.skip() pytest.fail('open of %s failed.' % name) subdatasets = ds.GetMetadata("SUBDATASETS") assert subdatasets, 'did not get expected subdataset count' ds = None for i in range(len(subdatasets) // 2): desc = subdatasets['SUBDATASET_%d_DESC' % (i + 1)] if desc == 'basic': name = subdatasets['SUBDATASET_%d_NAME' % (i + 1)] ds = gdal.Open(name) if ds is None: if gdaltest.gdalurlopen('http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/basic/0/0/0.png') is None: pytest.skip() pytest.fail('open of %s failed.' % name) ds = None
def stop_server(self): if self.running: if version_info >= (2,6,0): self.shutdown() else: gdaltest.gdalurlopen("http://127.0.0.1:%d/shutdown" % self.port) self.running = False
def server_stop(process, port): if isinstance(process, GDAL_ThreadedHttpServer): process.stop() return gdaltest.gdalurlopen('http://127.0.0.1:%d/shutdown' % port) gdaltest.wait_process(process)
def http_5(): drv = gdal.GetDriverByName('HTTP') if drv is None: return 'skip' ds = gdal.Open('https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/gdrivers/data/s4103.blx') if ds is None: conn = gdaltest.gdalurlopen('https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/gdrivers/data/s4103.blx') if conn is None: print('cannot open URL') return 'skip' try: conn.read() except: print('cannot read') return 'skip' conn.close() gdaltest.post_reason('fail') return 'fail' filename = ds.GetDescription() ds = None try: os.stat(filename) gdaltest.post_reason('file %s should have been removed' % filename) return 'fail' except OSError: pass return 'success'
def http_5(): try: drv = gdal.GetDriverByName( 'HTTP' ) except: drv = None if drv is None: return 'skip' ds = gdal.Open('http://svn.osgeo.org/gdal/trunk/autotest/gdrivers/data/s4103.blx') if ds is None: conn = gdaltest.gdalurlopen('http://svn.osgeo.org/gdal/trunk/autotest/gdrivers/data/s4103.blx') if conn is None: print('cannot open URL') return 'skip' try: conn.read() except: print('cannot read') return 'skip' conn.close() gdaltest.post_reason('fail') return 'fail' filename = ds.GetDescription() ds = None try: os.stat(filename) gdaltest.post_reason('file %s should have been removed' % filename) return 'fail' except: pass return 'success'
def wms_19(): if gdaltest.wms_drv is None: return 'skip' ds = gdal.Open('IIP:http://merovingio.c2rmf.cnrs.fr/fcgi-bin/iipsrv.fcgi?FIF=globe.256x256.tif') if ds is None: if gdaltest.gdalurlopen('http://merovingio.c2rmf.cnrs.fr/fcgi-bin/iipsrv.fcgi?FIF=globe.256x256.tif&obj=Basic-Info') is None: return 'skip' gdaltest.post_reason('open failed.') return 'fail' if ds.RasterXSize != 86400 \ or ds.RasterYSize != 43200 \ or ds.RasterCount != 3: gdaltest.post_reason('wrong size or bands') return 'fail' # Expected checksum seems to change over time. Hum... cs = ds.GetRasterBand(1).GetOverview(ds.GetRasterBand(1).GetOverviewCount() - 1).Checksum() if cs == 0: gdaltest.post_reason('Did not get expected checksum.') print(cs) return 'fail' ds = None return 'success'
def ogr_dods_1(): gdaltest.dods_ds = None ogrtest.dods_drv = ogr.GetDriverByName('DODS') if ogrtest.dods_drv is None: return 'skip' gdal.SetConfigOption('DODS_AIS_FILE', 'data/ais.xml') srv = 'http://www.epic.noaa.gov:10100/dods/wod2001/natl_prof_bot.cdp?&_id=1' if gdaltest.gdalurlopen(srv) is None: gdaltest.dods_ds = None return 'skip' gdaltest.dods_ds = ogr.Open('DODS:' + srv) if gdaltest.dods_ds is None: return 'fail' try: gdaltest.dods_profiles = gdaltest.dods_ds.GetLayerByName('profiles') gdaltest.dods_normalized = gdaltest.dods_ds.GetLayerByName('normalized') gdaltest.dods_lines = gdaltest.dods_ds.GetLayerByName('lines') except: gdaltest.dods_profiles = None gdaltest.dods_normalized = None if gdaltest.dods_profiles is None: gdaltest.dods_ds = None gdaltest.post_reason('profiles layer missing, likely AIS stuff not working.') return 'fail' return 'success'
def wms_10(): if gdaltest.wms_drv is None: return 'skip' name = "WMS:http://sedac.ciesin.columbia.edu/mapserver/map/GPWv3?" ds = gdal.Open( name ) if ds is None: srv = 'http://sedac.ciesin.columbia.edu/mapserver/map/GPWv3?' if gdaltest.gdalurlopen(srv) is None: return 'skip' gdaltest.post_reason( 'open of %s failed.' % name) return 'fail' subdatasets = ds.GetMetadata("SUBDATASETS") if len(subdatasets) == 0: gdaltest.post_reason( 'did not get expected subdataset count' ) print(subdatasets) return 'fail' ds = None name = subdatasets['SUBDATASET_1_NAME'] ds = gdal.Open( name ) if ds is None: gdaltest.post_reason( 'open of %s failed.' % name) return 'fail' ds = None return 'success'
def osr_url_test(url, expected_wkt): timeout = 10 socket.setdefaulttimeout(timeout) if gdaltest.gdalurlopen(url) is None: return 'skip' """Depend on the Accepts headers that ImportFromUrl sets to request SRS from sr.org""" srs = osr.SpatialReference() import gdal gdal.PushErrorHandler( 'CPLQuietErrorHandler' ) try: srs.ImportFromUrl( url ) except AttributeError: # old-gen bindings don't have this method yet return 'skip' except Exception: gdal.PopErrorHandler() if gdal.GetLastErrorMsg() == "GDAL/OGR not compiled with libcurl support, remote requests not supported." or \ gdal.GetLastErrorMsg().find("timed out") != -1: return 'skip' else: gdaltest.post_reason( 'exception: ' + gdal.GetLastErrorMsg() ) return 'fail' gdal.PopErrorHandler() if gdal.GetLastErrorMsg() == "GDAL/OGR not compiled with libcurl support, remote requests not supported." or \ gdal.GetLastErrorMsg().find("timed out") != -1: return 'skip' if not gdaltest.equal_srs_from_wkt( expected_wkt, srs.ExportToWkt() ): return 'fail' return 'success'
def ogr_wfs_deegree_sortby(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: return 'skip' ds = ogr.Open('WFS:http://deegree3-demo.deegree.org:80/utah-workspace/services?MAXFEATURES=10&VERSION=1.1.0') if ds is None: if gdaltest.gdalurlopen('http://deegree3-demo.deegree.org:80/utah-workspace/services') is None: print('cannot open URL') return 'skip' return 'fail' lyr = ds.ExecuteSQL("SELECT * FROM \"app:SGID024_Municipalities2004_edited\" ORDER BY OBJECTID DESC") feat = lyr.GetNextFeature() if feat.GetFieldAsInteger('OBJECTID') != 240: feat.DumpReadable() return 'fail' feat = lyr.GetNextFeature() if feat.GetFieldAsInteger('OBJECTID') != 239: feat.DumpReadable() return 'fail' ds.ReleaseResultSet(lyr) return 'success'
def http_1(): gdaltest.dods_drv = None try: drv = gdal.GetDriverByName( 'HTTP' ) except: drv = None if drv is None: return 'skip' try: gdaltest.dods_drv = gdal.GetDriverByName( 'DODS' ) if gdaltest.dods_drv is not None: gdaltest.dods_drv.Deregister() except: gdaltest.dods_drv = None tst = gdaltest.GDALTest( 'PNG','http://gdal.org/gdalicon.png', 1, 7617, filename_absolute = 1 ) ret = tst.testOpen() if ret == 'fail': conn = gdaltest.gdalurlopen('http://gdal.org/gdalicon.png') if conn is None: print('cannot open URL') return 'skip' conn.close() return ret
def http_4_old(): try: drv = gdal.GetDriverByName( 'HTTP' ) except: drv = None if drv is None: return 'skip' ds = gdal.Open('/vsicurl/ftp://ftp2.cits.rncan.gc.ca/pub/cantopo/250k_tif/MCR2010_01.tif') if ds is None: # Workaround unexplained failure on Tamas test machine. The test works fine with his # builds on other machines... # This heuristics might be fragile ! if "GDAL_DATA" in os.environ and os.environ["GDAL_DATA"].find("E:\\builds\\..\\sdk\\") == 0: return 'skip' conn = gdaltest.gdalurlopen('ftp://ftp2.cits.rncan.gc.ca/pub/cantopo/250k_tif/MCR2010_01.tif') if conn is None: print('cannot open URL') return 'skip' conn.close() return 'fail' filelist = ds.GetFileList() if filelist[0] != '/vsicurl/ftp://ftp2.cits.rncan.gc.ca/pub/cantopo/250k_tif/MCR2010_01.tif': print(filelist) return 'fail' return 'success'
def wms_9(): if gdaltest.wms_drv is None: pytest.skip() tms = """<GDAL_WMS> <Service name="TiledWMS"> <ServerUrl>http://onearth.jpl.nasa.gov/wms.cgi?</ServerUrl> <TiledGroupName>Global SRTM Elevation</TiledGroupName> </Service> </GDAL_WMS> """ ds = gdal.Open(tms) if ds is None: srv = 'http://onearth.jpl.nasa.gov/wms.cgi?' if gdaltest.gdalurlopen(srv) is None: pytest.skip() pytest.fail('open failed.') expected_cs = 5478 cs = ds.GetRasterBand(1).GetOverview(9).Checksum() assert cs == expected_cs, 'Did not get expected SRTM checksum.' ds = None
def test_http_4(): # Too unreliable if gdaltest.skip_on_travis(): pytest.skip() drv = gdal.GetDriverByName('HTTP') if drv is None: pytest.skip() ds = gdal.Open('/vsicurl/ftp://download.osgeo.org/gdal/data/gtiff/utm.tif') if ds is None: conn = gdaltest.gdalurlopen('ftp://download.osgeo.org/gdal/data/gtiff/utm.tif', timeout=4) if conn is None: pytest.skip('cannot open URL') try: conn.read() except: pytest.skip('cannot read') conn.close() if sys.platform == 'darwin' and gdal.GetConfigOption('TRAVIS', None) is not None: pytest.skip("Fails on MacOSX Travis sometimes. Not sure why.") pytest.fail() filelist = ds.GetFileList() assert '/vsicurl/ftp://download.osgeo.org/gdal/data/gtiff/utm.tif' in filelist
def test_wms_18(): if gdaltest.wms_drv is None: pytest.skip() # We don't need to check if the remote service is online as we # don't need a connection for this test. fn = '<GDAL_WMS><Service name="AGS"><ServerUrl>http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer</ServerUrl><BBoxOrder>xyXY</BBoxOrder><SRS>EPSG:3857</SRS></Service><DataWindow><UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY><LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY><SizeX>512</SizeX><SizeY>512</SizeY></DataWindow></GDAL_WMS>' ds = gdal.Open(fn) assert ds is not None, 'open failed.' assert ds.RasterXSize == 512 and ds.RasterYSize == 512 and ds.RasterCount == 3, \ 'wrong size or bands' # todo: add locationinfo test # add getting image test if gdaltest.gdalurlopen('http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer') is None: pytest.skip() expected_cs = 12824 cs = ds.GetRasterBand(1).Checksum() assert cs == expected_cs, 'Did not get expected SRTM checksum.' ds = None
def ogr_cloudant_init(): ogrtest.cloudant_drv = None try: ogrtest.cloudant_drv = ogr.GetDriverByName('Cloudant') except: pass if ogrtest.cloudant_drv is None: return 'skip' if 'CLOUDANT_TEST_SERVER' in os.environ: ogrtest.cloudant_test_server = os.environ['CLOUDANT_TEST_SERVER'] ogrtest.cloudant_test_url = ogrtest.cloudant_test_server else: ogrtest.cloudant_test_server = 'https://*****:*****@normanb.cloudant.com' ogrtest.cloudant_test_url = 'https://normanb.cloudant.com' ogrtest.cloudant_test_layer = 'gdaltest' if gdaltest.gdalurlopen(ogrtest.cloudant_test_url) is None: print('cannot open %s' % ogrtest.cloudant_test_url) ogrtest.cloudant_drv = None return 'skip' return 'success'
def test_wms_15(): if gdaltest.wms_drv is None: pytest.skip() src_ds = gdal.Open("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true") if src_ds is None: srv = 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true' if gdaltest.gdalurlopen(srv) is None: pytest.skip() pytest.fail() ds = gdal.GetDriverByName("WMS").CreateCopy("/vsimem/wms.xml", src_ds) src_ds = None if ds is None: return' fail' assert ds.RasterXSize == 1073741824 and ds.RasterYSize == 1073741824 and ds.RasterCount == 3, \ 'wrong size or bands' wkt = ds.GetProjectionRef() assert wkt.startswith('PROJCS["WGS 84 / Pseudo-Mercator"'), ('Got wrong SRS: ' + wkt) gt = ds.GetGeoTransform() assert abs(gt[0] - -20037508.342787001) <= 0.00001 and abs(gt[3] - 20037508.342787001) <= 0.00001 and abs(gt[1] - 0.037322767717361482) <= 0.00001 and abs(gt[2] - 0) <= 0.00001 and abs(gt[5] - -0.037322767717361482) <= 0.00001 and abs(gt[4] - 0) <= 0.00001, \ 'wrong geotransform' assert ds.GetRasterBand(1).GetOverviewCount() == 22, 'bad overview count' (block_xsize, block_ysize) = ds.GetRasterBand(1).GetBlockSize() if block_xsize != 256 or block_ysize != 256: print("(%d, %d)" % (block_xsize, block_ysize)) pytest.fail('bad block size') ds = None gdal.Unlink("/vsimem/wms.xml")
def wms_16(): if gdaltest.wms_drv is None: return 'skip' name = "WMS:http://demo.opengeo.org/geoserver/gwc/service/wms?tiled=TRUE" ds = gdal.Open( name ) if ds is None: srv = 'http://demo.opengeo.org/geoserver/gwc/service/wms?' if gdaltest.gdalurlopen(srv) is None: return 'skip' gdaltest.post_reason( 'open of %s failed.' % name) return 'fail' subdatasets = ds.GetMetadata("SUBDATASETS") if len(subdatasets) == 0: gdaltest.post_reason( 'did not get expected subdataset count' ) print(subdatasets) return 'fail' ds = None name = subdatasets['SUBDATASET_1_NAME'] ds = gdal.Open( name ) if ds is None: gdaltest.post_reason( 'open of %s failed.' % name) return 'fail' ds = None return 'success'
def http_6(): try: drv = gdal.GetDriverByName( 'HTTP' ) except: drv = None if drv is None: return 'skip' ds = ogr.Open('http://svn.osgeo.org/gdal/trunk/autotest/ogr/data/test.jml') if ds is None: conn = gdaltest.gdalurlopen('http://svn.osgeo.org/gdal/trunk/autotest/ogr/data/test.jml') if conn is None: print('cannot open URL') return 'skip' try: conn.read() except: print('cannot read') return 'skip' conn.close() gdaltest.post_reason('fail') return 'fail' ds = None return 'success'
def wms_9(): if gdaltest.wms_drv is None: return 'skip' tms = """<GDAL_WMS> <Service name="TiledWMS"> <ServerUrl>http://onearth.jpl.nasa.gov/wms.cgi?</ServerUrl> <TiledGroupName>Global SRTM Elevation</TiledGroupName> </Service> </GDAL_WMS> """ ds = gdal.Open(tms) if ds is None: srv = 'http://onearth.jpl.nasa.gov/wms.cgi?' if gdaltest.gdalurlopen(srv) is None: return 'skip' gdaltest.post_reason('open failed.') return 'fail' expected_cs = 5478 cs = ds.GetRasterBand(1).GetOverview(9).Checksum() if cs != expected_cs: gdaltest.post_reason('Did not get expected SRTM checksum.') print(cs) return 'fail' ds = None return 'success'
def http_4(): try: drv = gdal.GetDriverByName( 'HTTP' ) except: drv = None if drv is None: return 'skip' ds = gdal.Open('/vsicurl/ftp://ftp.remotesensing.org/gdal/data/gtiff/utm.tif') if ds is None: conn = gdaltest.gdalurlopen('ftp://ftp.remotesensing.org/gdal/data/gtiff/utm.tif') if conn is None: print('cannot open URL') return 'skip' try: conn.read() except: print('cannot read') return 'skip' conn.close() if sys.platform == 'darwin' and gdal.GetConfigOption('TRAVIS', None) is not None: print("Fails on MacOSX Travis sometimes. Not sure why.") return 'skip' gdaltest.post_reason('fail') return 'fail' filelist = ds.GetFileList() if '/vsicurl/ftp://ftp.remotesensing.org/gdal/data/gtiff/utm.tif' not in filelist: print(filelist) gdaltest.post_reason('fail') return 'fail' return 'success'
def wms_11(): if gdaltest.wms_drv is None: return 'skip' if gdaltest.skip_on_travis(): return 'skip' srv = 'http://onearth.jpl.nasa.gov/wms.cgi' if gdaltest.gdalurlopen(srv) is None: return 'skip' name = "WMS:http://onearth.jpl.nasa.gov/wms.cgi?request=GetTileService" ds = gdal.Open(name) if ds is None: gdaltest.post_reason('open of %s failed.' % name) return 'fail' subdatasets = ds.GetMetadata("SUBDATASETS") if not subdatasets: gdaltest.post_reason('did not get expected subdataset count') print(subdatasets) return 'fail' ds = None name = subdatasets['SUBDATASET_1_NAME'] ds = gdal.Open(name) if ds is None: gdaltest.post_reason('open of %s failed.' % name) return 'fail' ds = None return 'success'
def test_wms_11(): if gdaltest.wms_drv is None: pytest.skip() if gdaltest.skip_on_travis(): pytest.skip() srv = 'http://onearth.jpl.nasa.gov/wms.cgi' if gdaltest.gdalurlopen(srv) is None: pytest.skip() name = "WMS:http://onearth.jpl.nasa.gov/wms.cgi?request=GetTileService" ds = gdal.Open(name) assert ds is not None, ('open of %s failed.' % name) subdatasets = ds.GetMetadata("SUBDATASETS") assert subdatasets, 'did not get expected subdataset count' ds = None name = subdatasets['SUBDATASET_1_NAME'] ds = gdal.Open(name) assert ds is not None, ('open of %s failed.' % name) ds = None
def http_1(): gdaltest.dods_drv = None try: drv = gdal.GetDriverByName( 'HTTP' ) except: drv = None if drv is None: return 'skip' try: gdaltest.dods_drv = gdal.GetDriverByName( 'DODS' ) if gdaltest.dods_drv is not None: gdaltest.dods_drv.Deregister() except: gdaltest.dods_drv = None tst = gdaltest.GDALTest( 'GIF','http://home.gdal.org/~warmerda/frank.gif', 1, 35415, filename_absolute = 1 ) ret = tst.testOpen() if ret == 'failure': conn = gdaltest.gdalurlopen('http://home.gdal.org/~warmerda/frank.gif') if conn is None: print('cannot open URL') return 'skip' conn.close() return ret
def http_4(): try: drv = gdal.GetDriverByName( 'HTTP' ) except: drv = None if drv is None: return 'skip' ds = gdal.Open('/vsicurl/ftp://ftp.remotesensing.org/gdal/data/ehdr/elggll.bil') if ds is None: # Workaround unexplained failure on Tamas test machine. The test works fine with his # builds on other machines... # This heuristics might be fragile ! if "GDAL_DATA" in os.environ and os.environ["GDAL_DATA"].find("E:\\builds\\..\\sdk\\") == 0: return 'skip' conn = gdaltest.gdalurlopen('http://download.osgeo.org/gdal/data/ehdr/elggll.bil') if conn is None: print('cannot open URL') return 'skip' conn.close() return 'fail' filelist = ds.GetFileList() if filelist[1] != '/vsicurl/ftp://ftp.remotesensing.org/gdal/data/ehdr/elggll.hdr': print(filelist) return 'fail' return 'success'
def ogr_wfs_deegree_gml321(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: return 'skip' if gdaltest.gdalurlopen('http://deegree3-demo.deegree.org:80/inspire-workspace/services') is None: print('cannot open URL') return 'skip' ds = ogr.Open('WFS:http://deegree3-demo.deegree.org:80/inspire-workspace/services?ACCEPTVERSIONS=1.1.0&MAXFEATURES=10') if ds is None: if gdal.GetLastErrorMsg().find("Unable to determine the subcontroller for request type 'GetCapabilities' and service type 'WFS'") != -1: return 'skip' return 'fail' lyr = ds.GetLayerByName("cp:CadastralParcel") count = lyr.GetFeatureCount() if count != 10: print(count) return 'fail' lyr = ds.GetLayerByName("au:AdministrativeBoundary") count = lyr.GetFeatureCount() if count != 0: print(count) return 'fail' return 'success'
def ogr_wfs_deegree(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: return 'skip' if gdaltest.gdalurlopen('http://demo.deegree.org/deegree-wfs/services') is None: gdaltest.deegree_wfs = False print('cannot open URL') return 'skip' gdaltest.deegree_wfs = True ds = ogr.Open("WFS:http://demo.deegree.org/deegree-wfs/services?MAXFEATURES=10") if ds is None: gdaltest.post_reason('did not managed to open WFS datastore') return 'fail' lyr = ds.GetLayerByName('app:Springs') if lyr.GetName() != 'app:Springs': gdaltest.post_reason('did not get expected layer name') print(lyr.GetName()) return 'fail' sr = lyr.GetSpatialRef() sr2 = osr.SpatialReference() sr2.ImportFromEPSG(26912) if not sr.IsSame(sr2): gdaltest.post_reason('did not get expected SRS') print(sr) return 'fail' feat = lyr.GetNextFeature() geom = feat.GetGeometryRef() geom_wkt = geom.ExportToWkt() if feat.GetField('objectid') != 1 or \ ogrtest.check_feature_geometry(feat,'POINT (558750.703125 4402882.05)', max_error = 0.000000001 ) != 0: gdaltest.post_reason('did not get expected feature') feat.DumpReadable() return 'fail' # Test attribute filter ds = ogr.Open("WFS:http://demo.deegree.org/deegree-wfs/services") lyr = ds.GetLayerByName('app:Springs') lyr.SetAttributeFilter('objectid = 9 or objectid = 100 or (objectid >= 20 and objectid <= 30 and objectid != 27)') feat_count = lyr.GetFeatureCount() if feat_count != 12: gdaltest.post_reason('did not get expected feature count after SetAttributeFilter') print(feat_count) return 'fail' # Test attribute filter with gml_id lyr.SetAttributeFilter("gml_id = 'SGID024_Springs30' or gml_id = 'SGID024_Springs100'") feat_count = lyr.GetFeatureCount() if feat_count != 2: gdaltest.post_reason('did not get expected feature count after SetAttributeFilter (2)') print(feat_count) return 'fail' return 'success'
def wms_7(): if gdaltest.wms_drv is None: return 'skip' srv = 'http://tilecache.osgeo.org/wms-c/Basic.py' gdaltest.metacarta_tms = False if gdaltest.gdalurlopen(srv) is None: return 'skip' gdaltest.metacarta_tms = True tms = """<GDAL_WMS> <Service name="TMS"> <ServerUrl>http://tilecache.osgeo.org/wms-c/Basic.py</ServerUrl> <Layer>basic</Layer> <Format>png</Format> </Service> <DataWindow> <UpperLeftX>-180.0</UpperLeftX> <UpperLeftY>90.0</UpperLeftY> <LowerRightX>180.0</LowerRightX> <LowerRightY>-90.0</LowerRightY> <TileLevel>19</TileLevel> <TileCountX>2</TileCountX> <TileCountY>1</TileCountY> </DataWindow> <Projection>EPSG:4326</Projection> <BlockSizeX>256</BlockSizeX> <BlockSizeY>256</BlockSizeY> <BandsCount>3</BandsCount> </GDAL_WMS>""" ds = gdal.Open(tms) if ds is None: gdaltest.post_reason('open failed.') return 'fail' if ds.RasterXSize != 268435456 \ or ds.RasterYSize != 134217728 \ or ds.RasterCount != 3: gdaltest.post_reason('wrong size or bands') print(ds.RasterXSize) print(ds.RasterYSize) return 'fail' if ds.GetRasterBand(1).GetOverview(18).XSize != 512 \ or ds.GetRasterBand(1).GetOverview(18).YSize != 256: print(ds.GetRasterBand(1).GetOverview(18).XSize) print(ds.GetRasterBand(1).GetOverview(18).YSize) return 'fail' ds.GetRasterBand(1).GetOverview(18).ReadRaster(0, 0, 512, 256) ds = None return 'success'
def wms_15(): if gdaltest.wms_drv is None: return 'skip' src_ds = gdal.Open( "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true") if src_ds is None: srv = 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true' if gdaltest.gdalurlopen(srv) is None: return 'skip' return 'fail' ds = gdal.GetDriverByName("WMS").CreateCopy("/vsimem/wms.xml", src_ds) src_ds = None if ds is None: return' fail' if ds.RasterXSize != 134217728 \ or ds.RasterYSize != 134217728 \ or ds.RasterCount != 3: gdaltest.post_reason( 'wrong size or bands' ) return 'fail' wkt = ds.GetProjectionRef() if wkt.find('PROJCS["WGS 84 / Pseudo-Mercator"') != 0: gdaltest.post_reason( 'Got wrong SRS: ' + wkt ) return 'fail' gt = ds.GetGeoTransform() if abs(gt[0]- -20037508.342787001) > 0.00001 \ or abs(gt[3]- 20037508.342787001) > 0.00001 \ or abs(gt[1] - 0.298582141697407) > 0.00001 \ or abs(gt[2] - 0) > 0.00001 \ or abs(gt[5] - -0.298582141697407) > 0.00001 \ or abs(gt[4] - 0) > 0.00001: gdaltest.post_reason( 'wrong geotransform' ) print(gt) return 'fail' if ds.GetRasterBand(1).GetOverviewCount() != 19: gdaltest.post_reason( 'bad overview count' ) print(ds.GetRasterBand(1).GetOverviewCount()) return 'fail' (block_xsize, block_ysize) = ds.GetRasterBand(1).GetBlockSize() if block_xsize != 256 or block_ysize != 256: gdaltest.post_reason( 'bad block size' ) print("(%d, %d)" % (block_xsize, block_ysize)) return 'fail' ds = None gdal.Unlink("/vsimem/wms.xml") return 'success'
def test_wms_13(): if gdaltest.wms_drv is None: pytest.skip() ds = gdal.Open("data/wms/DNEC_250K.vrt") if ds.ReadRaster(0, 0, 1024, 682) is None: srv = 'http://wms.geobase.ca/wms-bin/cubeserv.cgi?SERVICE=WMS&VERSION=1.1.1&REQUEST=GeCapabilities' if gdaltest.gdalurlopen(srv) is None: pytest.skip() pytest.fail() ds = None
def ogr_wfs_deegree_wfs200(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: return 'skip' ds = ogr.Open('WFS:http://deegree3-testing.deegree.org:80/utah-workspace/services?ACCEPTVERSIONS=2.0.0') if ds is None: if gdaltest.gdalurlopen('http://deegree3-testing.deegree.org:80/utah-workspace/services?ACCEPTVERSIONS=2.0.0') is None: print('cannot open URL') return 'skip' return 'fail' lyr = ds.GetLayerByName("app:SGID024_Municipalities2004_edited") lyr.SetAttributeFilter('OBJECTID = 5') count = lyr.GetFeatureCount() if count != 1: gdaltest.post_reason("OBJECTID = 5 filter failed") print(count) return 'fail' feat = lyr.GetNextFeature() if feat.GetFieldAsInteger('OBJECTID') != 5: gdaltest.post_reason("OBJECTID = 5 filter failed") feat.DumpReadable() return 'fail' lyr.SetAttributeFilter("gml_id = 'SGID024_MUNICIPALITIES2004_EDITED_5'") count = lyr.GetFeatureCount() if count != 1: gdaltest.post_reason("gml_id = 'SGID024_MUNICIPALITIES2004_EDITED_5' filter failed") print(count) return 'fail' feat = lyr.GetNextFeature() if feat.GetFieldAsInteger('OBJECTID') != 6: gdaltest.post_reason("gml_id = 'SGID024_MUNICIPALITIES2004_EDITED_5' filter failed") feat.DumpReadable() return 'fail' lyr.SetAttributeFilter(None) lyr.SetSpatialFilterRect(-1e8,-1e8,1e8,1e8) spatialfiltercount = lyr.GetFeatureCount() lyr.SetSpatialFilter(None) allcount = lyr.GetFeatureCount() if allcount != spatialfiltercount or allcount == 0: gdaltest.post_reason('spatialfiltercount != allcount') print(spatialfiltercount) print(allcount) return 'fail' return 'success'
def startup_and_cleanup(): if 'CLOUDANT_TEST_SERVER' in os.environ: ogrtest.cloudant_test_server = os.environ['CLOUDANT_TEST_SERVER'] ogrtest.cloudant_test_url = ogrtest.cloudant_test_server else: ogrtest.cloudant_test_server = 'https://*****:*****@normanb.cloudant.com' ogrtest.cloudant_test_url = 'https://normanb.cloudant.com' ogrtest.cloudant_test_layer = 'gdaltest' if gdaltest.gdalurlopen(ogrtest.cloudant_test_url) is None: pytest.skip('cannot open %s' % ogrtest.cloudant_test_url)
def ogr_wfs_geoserver_shapezip(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: if gdaltest.geoserver_wfs is None: if gdaltest.gdalurlopen('http://demo.opengeo.org/geoserver/wfs') is None: gdaltest.geoserver_wfs = False print('cannot open URL') return 'skip' gdaltest.geoserver_wfs = True if gdaltest.geoserver_wfs != True: return 'skip' ds = ogr.Open('WFS:http://demo.opengeo.org/geoserver/wfs?TYPENAME=za:za_points&MAXFEATURES=10&VERSION=1.1.0&OUTPUTFORMAT=SHAPE-ZIP') if ds is None: gdaltest.post_reason('did not managed to open WFS datastore') return 'fail' if ds.GetLayerCount() != 1: gdaltest.post_reason('did not get expected layer count') print(ds.GetLayerCount()) return 'fail' lyr = ds.GetLayer(0) if lyr.GetName() != 'za:za_points': gdaltest.post_reason('did not get expected layer name') print(lyr.GetName()) return 'fail' feat_count = lyr.GetFeatureCount() if feat_count != 10: gdaltest.post_reason('did not get expected feature count') print(feat_count) return 'fail' if not lyr.TestCapability(ogr.OLCFastFeatureCount): gdaltest.post_reason('did not get OLCFastFeatureCount') return 'fail' feat = lyr.GetNextFeature() geom = feat.GetGeometryRef() geom_wkt = geom.ExportToWkt() #if feat.GetField('name') != 'Alexander Bay' or \ if ogrtest.check_feature_geometry(feat,'POINT (16.4827778 -28.5947222)', max_error = 0.000000001 ) != 0: gdaltest.post_reason('did not get expected feature') feat.DumpReadable() return 'fail' return 'success'
def test_ogr_gft_init(): ogrtest.gft_drv = None ogrtest.gft_drv = ogr.GetDriverByName('GFT') if ogrtest.gft_drv is None: pytest.skip() if gdaltest.gdalurlopen('http://www.google.com') is None: ogrtest.gft_drv = None pytest.skip('cannot open http://www.google.com') ogrtest.gft_refresh = '1/woRTxgfN8dLUpRhnOL-BXG-f7VxzXKy_3D5eizH8bS8'
def test_twms_GIBS(): # if not gdaltest.run_slow_tests(): # pytest.skip() baseURL = "https://gibs.earthdata.nasa.gov/twms/epsg4326/best/twms.cgi?" try: subdatasets = gdaltest.subdatasets except: pytest.skip() # Connects to the server ds = gdal.Open(subdatasets['SUBDATASET_1_NAME']) if ds is None and gdaltest.gdalurlopen(baseURL + "request=GetTileService"): pytest.fail() ds = None # Connects to the server options = ["Change=time:2021-02-10"] ds = gdal.OpenEx(subdatasets['SUBDATASET_1_NAME'], open_options=options) if ds is None and gdaltest.gdalurlopen(baseURL + "request=GetTileService"): pytest.fail() ds = None
def ogr_wfs_mapserver(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: return 'skip' if gdaltest.gdalurlopen( 'http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap') is None: print('cannot open URL') return 'skip' ds = ogr.Open('WFS:http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap') if ds is None: gdaltest.post_reason('did not managed to open WFS datastore') return 'skip' if ds.GetLayerCount() != 2: gdaltest.post_reason('did not get expected layer count') print(ds.GetLayerCount()) return 'fail' lyr = ds.GetLayer(0) if lyr.GetName() != 'park': gdaltest.post_reason('did not get expected layer name') print(lyr.GetName()) return 'fail' sr = lyr.GetSpatialRef() sr2 = osr.SpatialReference() sr2.ImportFromEPSG(42304) if not sr.IsSame(sr2): gdaltest.post_reason('did not get expected SRS') print(sr) return 'fail' feat_count = lyr.GetFeatureCount() if feat_count != 46: gdaltest.post_reason('did not get expected feature count') print(feat_count) return 'fail' feat = lyr.GetNextFeature() geom = feat.GetGeometryRef() geom_wkt = geom.ExportToWkt() if geom_wkt.find("POLYGON ((389366.84375 3791519.75") == -1: gdaltest.post_reason('did not get expected feature') feat.DumpReadable() return 'fail' return 'success'
def wms_13(): if gdaltest.wms_drv is None: return 'skip' ds = gdal.Open("data/DNEC_250K.vrt") if ds.ReadRaster(0, 0, 1024, 682) is None: srv = 'http://wms.geobase.ca/wms-bin/cubeserv.cgi?SERVICE=WMS&VERSION=1.1.1&REQUEST=GeCapabilities' if gdaltest.gdalurlopen(srv) is None: return 'skip' return 'fail' ds = None return 'success'
def wms_17(): srv = 'http://onmoon.lmmp.nasa.gov/sites/wms.cgi?' if gdaltest.gdalurlopen(srv) is None: pytest.skip() name = '<GDAL_WMS><Service name="TiledWMS"><ServerUrl>http://onmoon.lmmp.nasa.gov/sites/wms.cgi?</ServerUrl><TiledGroupName>King Crater DEM Color Confidence, LMMP</TiledGroupName></Service></GDAL_WMS>' ds = gdal.Open(name) assert ds is not None, ('open of %s failed.' % name) band = ds.GetRasterBand(1) assert band.GetColorTable() is not None ds = None
def wms_12(): if gdaltest.wms_drv is None: return 'skip' if gdaltest.metacarta_tms is not True: return 'skip' name = "http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/" ds = gdal.Open(name) if ds is None: if gdaltest.gdalurlopen('http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/basic/0/0/0.png') is None: return 'skip' gdaltest.post_reason('open of %s failed.' % name) return 'fail' subdatasets = ds.GetMetadata("SUBDATASETS") if not subdatasets: gdaltest.post_reason('did not get expected subdataset count') print(subdatasets) return 'fail' ds = None for i in range(len(subdatasets) // 2): desc = subdatasets['SUBDATASET_%d_DESC' % (i + 1)] if desc == 'basic': name = subdatasets['SUBDATASET_%d_NAME' % (i + 1)] ds = gdal.Open(name) if ds is None: if gdaltest.gdalurlopen('http://tilecache.osgeo.org/wms-c/Basic.py/1.0.0/basic/0/0/0.png') is None: return 'skip' gdaltest.post_reason('open of %s failed.' % name) return 'fail' ds = None return 'success'
def test_wcs_1(): # Disable wcs tests till we have a more reliable test server. gdaltest.wcs_drv = gdal.GetDriverByName('WCS') # NOTE - mloskot: # This is a dirty hack checking if remote WCS service is online. # Nothing genuine but helps to keep the buildbot waterfall green. srv = 'http://demo.opengeo.org/geoserver/wcs?' if gdaltest.gdalurlopen(srv) is None: gdaltest.wcs_drv = None gdaltest.wcs_ds = None if gdaltest.wcs_drv is None: pytest.skip()
def test_http_3(): drv = gdal.GetDriverByName('HTTP') if drv is None: pytest.skip() gdal.SetConfigOption('GDAL_HTTP_TIMEOUT', '5') ds = gdal.Open('/vsicurl/http://download.osgeo.org/gdal/data/ehdr/elggll.bil') gdal.SetConfigOption('GDAL_HTTP_TIMEOUT', None) if ds is None: conn = gdaltest.gdalurlopen('http://download.osgeo.org/gdal/data/ehdr/elggll.bil') if conn is None: pytest.skip('cannot open URL') conn.close() pytest.fail()
def test_http_2(): drv = gdal.GetDriverByName('HTTP') if drv is None: pytest.skip() tst = gdaltest.GDALTest('GTiff', '/vsicurl/https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/gcore/data/byte.tif', 1, 4672, filename_absolute=1) ret = tst.testOpen() if ret == 'fail': conn = gdaltest.gdalurlopen('https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/gcore/data/byte.tif') if conn is None: pytest.skip('cannot open URL') conn.close() return ret
def ogr_gme_init(): ogrtest.gme_drv = None try: ogrtest.gme_refresh = os.environ['GME_REFRESH_TOKEN'] ogrtest.gme_drv = ogr.GetDriverByName('GME') except: return 'skip' if gdaltest.gdalurlopen('http://www.google.com') is None: print('cannot open http://www.google.com') ogrtest.gme_drv = None return 'skip' return 'success'
def test_ogr_dods_5(): if ogrtest.dods_drv is None: pytest.skip() srv = 'http://uhslc1.soest.hawaii.edu/cgi-bin/nph-nc/fast/m004.nc.dds' if gdaltest.gdalurlopen(srv) is None: pytest.skip() grid_ds = ogr.Open('DODS:' + srv) assert grid_ds is not None lat_lyr = grid_ds.GetLayerByName('latitude') expect = [-0.53166663646698] tr = ogrtest.check_features_against_list(lat_lyr, 'latitude', expect) assert tr != 0
def test_ogr_couchdb_init(): ogrtest.couchdb_drv = None ogrtest.couchdb_drv = ogr.GetDriverByName('CouchDB') if ogrtest.couchdb_drv is None: pytest.skip() if 'COUCHDB_TEST_SERVER' in os.environ: ogrtest.couchdb_test_server = os.environ['COUCHDB_TEST_SERVER'] else: ogrtest.couchdb_test_server = 'http://127.0.0.1:5984' ogrtest.couchdb_temp_layer_name = 'layer_' + str(uuid.uuid1()).replace('-', '_') if gdaltest.gdalurlopen(ogrtest.couchdb_test_server) is None: ogrtest.couchdb_drv = None pytest.skip('cannot open %s' % ogrtest.couchdb_test_server)
def ogr_wfs_ionic_wfst(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: return 'skip' if gdaltest.gdalurlopen( 'http://webservices.ionicsoft.com/ionicweb/wfs/BOSTON_ORA' ) is None: print('cannot open URL') gdaltest.ionic_wfs = False return 'skip' gdaltest.ionic_wfs = True ds = ogr.Open( 'WFS:http://webservices.ionicsoft.com/ionicweb/wfs/BOSTON_ORA', update=1) if ds is None: if gdal.GetLastErrorMsg().find('HTTP error code : 403') != -1: gdaltest.ionic_wfs = False return 'skip' return 'fail' lyr = ds.GetLayerByName('wfs:BUSINESS') geom = ogr.CreateGeometryFromWkt('POINT(234000 890000)') feat = ogr.Feature(lyr.GetLayerDefn()) feat.SetGeometry(geom) feat.SetField('NAME', 'nameSetByOGR') feat.SetField('TOTAL_EMPLOYEES', '10') ret = lyr.CreateFeature(feat) if ret != 0: print('fail on CreateFeature') return 'fail' gmlid = feat.GetField('gml_id') ret = lyr.SetFeature(feat) if ret != 0: print('fail on SetFeature') return 'fail' ds.ExecuteSQL("DELETE FROM wfs:BUSINESS WHERE gml_id = '%s'" % gmlid) return 'success'
def ogr_gft_init(): ogrtest.gft_drv = None ogrtest.gft_drv = ogr.GetDriverByName('GFT') if ogrtest.gft_drv is None: return 'skip' if gdaltest.gdalurlopen('http://www.google.com') is None: print('cannot open http://www.google.com') ogrtest.gft_drv = None return 'skip' ogrtest.gft_refresh = '1/woRTxgfN8dLUpRhnOL-BXG-f7VxzXKy_3D5eizH8bS8' return 'success'
def startup_and_cleanup(): if 'COUCHDB_TEST_SERVER' in os.environ: ogrtest.couchdb_test_server = os.environ['COUCHDB_TEST_SERVER'] else: ogrtest.couchdb_test_server = 'http://127.0.0.1:5984' ogrtest.couchdb_temp_layer_name = 'layer_' + str(uuid.uuid1()).replace( '-', '_') if gdaltest.gdalurlopen(ogrtest.couchdb_test_server) is None: pytest.skip('cannot open %s' % ogrtest.couchdb_test_server) yield ds = ogr.Open('couchdb:%s' % ogrtest.couchdb_test_server, update=1) assert ds is not None ds.ExecuteSQL('DELLAYER:' + ogrtest.couchdb_temp_layer_name)
def test_wms_19(): ds = gdal.Open('IIP:http://merovingio.c2rmf.cnrs.fr/fcgi-bin/iipsrv.fcgi?FIF=globe.256x256.tif') if ds is None: if gdaltest.gdalurlopen('http://merovingio.c2rmf.cnrs.fr/fcgi-bin/iipsrv.fcgi?FIF=globe.256x256.tif&obj=Basic-Info') is None: pytest.skip() pytest.fail('open failed.') assert ds.RasterXSize == 86400 and ds.RasterYSize == 43200 and ds.RasterCount == 3, \ 'wrong size or bands' # Expected checksum seems to change over time. Hum... cs = ds.GetRasterBand(1).GetOverview(ds.GetRasterBand(1).GetOverviewCount() - 1).Checksum() assert cs != 0, 'Did not get expected checksum.' ds = None
def test_wms_7(): if gdaltest.wms_drv is None: pytest.skip() srv = 'http://tilecache.osgeo.org/wms-c/Basic.py' gdaltest.metacarta_tms = False if gdaltest.gdalurlopen(srv) is None: pytest.skip() gdaltest.metacarta_tms = True tms = """<GDAL_WMS> <Service name="TMS"> <ServerUrl>http://tilecache.osgeo.org/wms-c/Basic.py</ServerUrl> <Layer>basic</Layer> <Format>png</Format> </Service> <DataWindow> <UpperLeftX>-180.0</UpperLeftX> <UpperLeftY>90.0</UpperLeftY> <LowerRightX>180.0</LowerRightX> <LowerRightY>-90.0</LowerRightY> <TileLevel>19</TileLevel> <TileCountX>2</TileCountX> <TileCountY>1</TileCountY> </DataWindow> <Projection>EPSG:4326</Projection> <BlockSizeX>256</BlockSizeX> <BlockSizeY>256</BlockSizeY> <BandsCount>3</BandsCount> </GDAL_WMS>""" ds = gdal.Open(tms) assert ds is not None, 'open failed.' assert ds.RasterXSize == 268435456 and ds.RasterYSize == 134217728 and ds.RasterCount == 3, \ 'wrong size or bands' assert ds.GetRasterBand(1).GetOverview( 18).XSize == 512 and ds.GetRasterBand(1).GetOverview(18).YSize == 256 ds.GetRasterBand(1).GetOverview(18).ReadRaster(0, 0, 512, 256) ds = None
def http_3(): drv = gdal.GetDriverByName('HTTP') if drv is None: return 'skip' gdal.SetConfigOption('GDAL_HTTP_TIMEOUT', '5') ds = gdal.Open('/vsicurl/http://download.osgeo.org/gdal/data/ehdr/elggll.bil') gdal.SetConfigOption('GDAL_HTTP_TIMEOUT', None) if ds is None: conn = gdaltest.gdalurlopen('http://download.osgeo.org/gdal/data/ehdr/elggll.bil') if conn is None: print('cannot open URL') return 'skip' conn.close() return 'fail' return 'success'
def test_http_6(): drv = gdal.GetDriverByName('HTTP') if drv is None: pytest.skip() ds = ogr.Open('https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/ogr/data/test.jml') if ds is None: conn = gdaltest.gdalurlopen('https://raw.githubusercontent.com/OSGeo/gdal/master/autotest/ogr/data/test.jml') if conn is None: pytest.skip('cannot open URL') try: conn.read() except: pytest.skip('cannot read') conn.close() pytest.fail() ds = None
def ogr_csw_pycsw(): if gdaltest.csw_drv is None: return 'skip' ds = ogr.Open('CSW:http://catalog.data.gov/csw') if ds is None: if gdaltest.gdalurlopen('http://catalog.data.gov/csw') is None: print('cannot open URL') return 'skip' gdaltest.post_reason('did not managed to open CSW datastore') return 'skip' lyr = ds.GetLayer(0) f = lyr.GetNextFeature() if f is None: gdaltest.post_reason('did not get expected layer name') return 'fail' return 'success'
def test_ogr_carto_test_ogrsf(): if gdal.GetConfigOption('SKIP_SLOW') is not None: pytest.skip() ogrtest.carto_test_server = 'https://gdalautotest2.carto.com' if gdaltest.gdalurlopen(ogrtest.carto_test_server) is None: pytest.skip('cannot open %s' % ogrtest.carto_test_server) import test_cli_utilities if test_cli_utilities.get_test_ogrsf_path() is None: pytest.skip() ret = gdaltest.runexternal( test_cli_utilities.get_test_ogrsf_path() + ' --config CARTO_HTTPS NO --config CARTO_PAGE_SIZE 300 -ro "CARTO:gdalautotest2 tables=tm_world_borders_simpl_0_3"' ) assert ret.find('INFO') != -1 and ret.find('ERROR') == -1
def wms_2(): #Set the driver so we don't have to search it by name again gdaltest.wms_drv = gdal.GetDriverByName('WMS') # NOTE - mloskot: # This is a dirty hack checking if remote WMS service is online. # Nothing genuine but helps to keep the buildbot waterfall green. srv = 'http://sedac.ciesin.columbia.edu/mapserver/map/GPWv3?' gdaltest.wms_srv1_ok = gdaltest.gdalurlopen(srv) is not None gdaltest.wms_ds = None if not gdaltest.wms_srv1_ok: pytest.skip() gdaltest.wms_ds = gdal.Open('data/wms/pop_wms.xml') if gdaltest.wms_ds is None: pytest.fail('open failed.')
def ogr_wfs_deegree_wfst(): if gdaltest.wfs_drv is None: return 'skip' if not gdaltest.have_gml_reader: return 'skip' if gdaltest.gdalurlopen( 'http://testing.deegree.org/deegree-wfs/services') is None: print('cannot open URL') return 'skip' ds = ogr.Open('WFS:http://testing.deegree.org/deegree-wfs/services', update=1) if ds is None: return 'fail' lyr = ds.GetLayerByName('app:CountyBoundaries_edited') geom = ogr.CreateGeometryFromWkt('POINT(2 49)') feat = ogr.Feature(lyr.GetLayerDefn()) feat.SetGeometry(geom) feat.SetField('name', 'nameSetByOGR') feat.SetField('fips', '10') feat.SetField('feature_id', '123456') feat.SetField('objectid', '7890123') feat.SetField('shape_area', 12.34) feat.SetField('shape_len', 56.78) ret = lyr.CreateFeature(feat) if ret != 0: print('expected fail on CreateFeature') ret = lyr.DeleteFeature(1) if ret != 0: print('expected fail on DeleteFeature') feat = lyr.GetFeature(10) ret = lyr.SetFeature(feat) if ret != 0: print('expected fail on SetFeature') return 'success'
def test_wms_18(): if gdaltest.wms_drv is None: pytest.skip() # We don't need to check if the remote service is online as we # don't need a connection for this test. fn = '<GDAL_WMS><Service name="AGS"><ServerUrl>http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer</ServerUrl><BBoxOrder>xyXY</BBoxOrder><SRS>EPSG:3857</SRS></Service><DataWindow><UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY><LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY><SizeX>512</SizeX><SizeY>512</SizeY></DataWindow></GDAL_WMS>' ds = gdal.Open(fn) assert ds is not None, 'open failed.' assert ds.RasterXSize == 512 and ds.RasterYSize == 512 and ds.RasterCount == 3, \ 'wrong size or bands' # todo: add locationinfo test # add getting image test if not gdaltest.gdalurlopen( 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer' ): ds = None pytest.skip() expected_cs = 12824 cs = ds.GetRasterBand(1).Checksum() assert cs == expected_cs, 'Did not get expected checksum.' ds = None # Alternative url with additional parameters fn = '<GDAL_WMS><Service name="AGS"><ServerUrl>http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export?dpi=96&layerdefs=&layerTimeOptions=&dynamicLayers=&</ServerUrl><BBoxOrder>xyXY</BBoxOrder><SRS>EPSG:3857</SRS></Service><DataWindow><UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY><LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY><SizeX>512</SizeX><SizeY>512</SizeY></DataWindow></GDAL_WMS>' ds = gdal.Open(fn) assert ds is not None, 'open failed.' assert ds.RasterXSize == 512 and ds.RasterYSize == 512 and ds.RasterCount == 3, \ 'wrong size or bands' cs = ds.GetRasterBand(1).Checksum() assert cs == expected_cs, 'Did not get expected checksum.' ds = None
def ogr_cartodb_init(): ogrtest.cartodb_drv = None try: ogrtest.cartodb_drv = ogr.GetDriverByName('CartoDB') except: pass if ogrtest.cartodb_drv is None: return 'skip' ogrtest.cartodb_test_server = 'https://gdalautotest2.cartodb.com' if gdaltest.gdalurlopen(ogrtest.cartodb_test_server) is None: print('cannot open %s' % ogrtest.cartodb_test_server) ogrtest.cartodb_drv = None return 'skip' return 'success'