コード例 #1
0
def main():
    # The execution directory
    exedir = os.getcwd()
    # An iterator over the geometries in the GeoPackage
    gc = ocgis.GeomCabinetIterator(
        path=GEOPKG, driver_kwargs={'feature_class': 'Catchment'})
    # Number of records in the GeoPackage
    len_gc = len(gc)
    for ctr, record in enumerate(gc):
        # Print an update every 100 iterations
        if ctr % 100 == 0:
            print('INFO: Index {} of {}'.format(ctr, len_gc))
        do_record_test(exedir, record)
コード例 #2
0
def extract_basins():
    '''
    Extract basin using OCGIS
    '''
    logger.info('Extracting basin {}'.format(basin))

    if GEOM is None:
        select_ugid = None
    else:
        select_geom = filter(lambda x: x['properties']['basin'] == basin,
                             ocgis.GeomCabinetIterator(path=SHAPEFILE_PATH))
        ## this argument must always come in as a list
        select_ugid = [select_geom[0]['properties']['UGID']]
    ## parameterize the operations to be performed on the target dataset
    ops = ocgis.OcgOperations(dataset=rd,
                              geom=SHAPEFILE_PATH,
                              aggregate=False,
                              snippet=False,
                              select_ugid=select_ugid,
                              output_format=output_format,
                              prefix=prefix,
                              dir_output=odir)
    ret = ops.execute()
コード例 #3
0

## connect to the dataset and load the data as a field object. this will be used
## to iterate over time coordinates during the conversion step.
rd = ocgis.RequestDataset(uri=URI,variable=VARIABLE)
field = rd.get()

## selecting specific geometries from a shapefile requires knowing the target
## geometry's UGID inside the shapefile. shapefile are required to have this
## identifier at this time as a full attribute search is not enabled. this code
## searches for TX to find the UGID associated with that state.
if GEOM is None:
    select_ugid = None
else:
    select_geom = filter(lambda x: x['properties']['STATE_ABBR'] == 'TX',
                         ocgis.GeomCabinetIterator(path=SHAPEFILE_PATH))
    ## this argument must always come in as a list
    select_ugid = [select_geom[0]['properties']['UGID']]
    
## USE OCGIS OPERATIONS ########################################################

## get an example time coordinate
centroid = field.temporal.value_datetime[0]
print('writing geojson for time slice: {0}'.format(centroid))
## this again is the target dataset with a time range for subsetting now
rd = ocgis.RequestDataset(uri=URI,variable=VARIABLE,time_range=[centroid,centroid])
## name of the output geojson file
prefix = 'ocgis_output_{0}'.format(OUTPUT_FORMAT)
## parameterize the operations to be performed on the target dataset
ops = ocgis.OcgOperations(dataset=rd,geom=SHAPEFILE_PATH,select_ugid=select_ugid,
                          output_format=OUTPUT_FORMAT,prefix=prefix,dir_output=DIR_OUTPUT,
コード例 #4
0
ファイル: clip_RUS.py プロジェクト: hzy9981/flyingpigeon
PATH_NC = [join(p, nc) for nc in listdir(p)]

PATH_NC.sort()

SH_PATH = shapefiles_path()
GEOM_PATH = join(SH_PATH, 'countries.shp')
# GEOM_PATH = '/home/benkoziol/l/project/ocg/bin/shp/world_countries/world_countries.shp'
ocgis.env.DIR_OUTPUT = '/home/nils/data/'
ocgis.env.OVERWRITE = True

rd = ocgis.RequestDataset(PATH_NC)

# We do not want to update the coordinate system from WGS84 to Spherical. This causes issues with wrapping for unknown
# reasons. We also need to union the geometries to remove other inconsistencies requiring the unwrapping occur outside
# the operations call.
gc = ocgis.GeomCabinetIterator(path=GEOM_PATH, select_sql_where="ADMIN = 'Russia'", as_field=True)

subset_field = list(gc)[0]

shapely_geom = subset_field.geom.get_value()[0]
wrapper = ocgis.spatial.wrap.GeometryWrapper()
unwrapped = wrapper.unwrap(shapely_geom)
subset_field.geom.get_value()[0] = cascaded_union([g for g in unwrapped])
subset_field.set_crs(rd.crs)
# subset_field.set_crs(ocgis.crs.Spherical())

# Subset the netCDF file and write to disk.
ops = ocgis.OcgOperations(dataset=rd, geom=subset_field, snippet=True, output_format='nc', prefix='ocgis-russia-subset')
ret = ops.execute()

# Convert the subset netCDF file to ESRI shapefile.