示例#1
0
def do(gs_handle, layer_alias, lat, lon, search_dist_meters):
    input_table = create_query_input_table(7, lat, lon)

    layer_alias_field_map = pxpointsc.geospatial_prepare(gs_handle, r'f:\websites\datacatalog.xml', r'f:\pxse-data', [ layer_alias ])
    output_columns = '[{a}]INPUT.Id;'.format(a=layer_alias) + ';'.join(layer_alias_field_map[layer_alias])

    proc_opts = 'InputGeoColumn=InputGeometry'
    if search_dist_meters <= 0:
        proc_opts = ';'.join([proc_opts, '[{a}]{o}'.format(a=layer_alias, o=pxcommon.get_spatial_relation_spec(pxcommon.SpatialRelation.WITHIN))])
    else:
        proc_opts = ';'.join([proc_opts, '[{a}]{o}'.format(a=layer_alias, o='FindNearest=T;[{a}]Distance={m}'.format(a=layer_alias, m=search_dist_meters))])

    error_cols = ERROR_TABLE_COLUMNS_DEF.replace('$', '[{a}]$'.format(a=layer_alias))
    (output_table, error_table, return_code, return_message) = pxpointsc.geospatial_query(
        gs_handle,
        input_table,
        output_columns,
        error_cols,
        proc_opts
    )
    if output_table != None and output_table.nrows > 0:
        print('Query OK')
        for i in range(output_table.nrows()):
            row = output_table.rows[i]
            for j in range(output_table.ncols()):
                print(output_table.col_names[j] + ': ' + str(row[j]))
    else:
        print(return_message)
示例#2
0
def query(gs_handle, layer_path, layer_alias, lat, lon, search_dist_meters, attach=True):
    input_table = create_query_input_table(7, lat, lon)
    print(input_table.ncols())
    print(input_table.rows[0])
    # attach the layer
    if attach:
        (return_code, return_message) = pxpointsc.geospatial_attach_layer(gs_handle, layer_path, layer_alias)
        if return_code != 0:
            raise RuntimeError('Code: {c}. Message: {m}'.format(c=return_code, m=return_message))

    # get the layer attributes
    fields = pxpointsc.geospatial_layer_info(gs_handle, layer_alias)
    fields = ['[{a}]{f}'.format(a=layer_alias, f=x) for x in fields]
    output_columns = '[County]INPUT.Id;' + ';'.join(fields)

    # pdb.set_trace()
    # query using these attributes
    proc_opts = 'InputGeoColumn=InputGeometry'
    if search_dist_meters <= 0:
        proc_opts = ';'.join([proc_opts, '[{a}]{o}'.format(a=layer_alias, o=pxcommon.get_spatial_relation_spec(pxcommon.SpatialRelation.WITHIN))])
    else:
        proc_opts = ';'.join([proc_opts, '[{a}]{o}'.format(a=layer_alias, o='FindNearest=T;[{a}]Distance={m}'.format(a=layer_alias, m=search_dist_meters))])

    error_cols = ERROR_TABLE_COLUMNS_DEF.replace('$', '[{a}]$'.format(a=layer_alias))
    print('Output cols: ' + output_columns)
    print('Query options: ' + proc_opts)
    print('Error cols: ' + error_cols)
    (output_table, error_table, return_code, return_message) = pxpointsc.geospatial_query(
        gs_handle,
        input_table,
        output_columns,
        error_cols,
        proc_opts
    )
    if output_table != None and output_table.nrows > 0:
        print('Query OK')
        for i in range(output_table.nrows()):
            row = output_table.rows[i]
            for j in range(output_table.ncols()):
                print(output_table.col_names[j] + ': ' + str(row[j]))
    else:
        print(return_message)