def find(self, searchText, layers, contains=True, searchFields="", sr="", layerDefs="", returnGeometry=True, maxAllowableOffset="", geometryPrecision="", dynamicLayers="", returnZ=False, returnM=False, gdbVersion=""): """ performs the map service find operation """ url = self._url + "/find" #print url params = { "f" : "json", "searchText" : searchText, "contains" : self._convert_boolean(contains), "searchFields": searchFields, "sr" : sr, "layerDefs" : layerDefs, "returnGeometry" : self._convert_boolean(returnGeometry), "maxAllowableOffset" : maxAllowableOffset, "geometryPrecision" : geometryPrecision, "dynamicLayers" : dynamicLayers, "returnZ" : self._convert_boolean(returnZ), "returnM" : self._convert_boolean(returnM), "gdbVersion" : gdbVersion, "layers" : layers } if not self._token is None and \ self._token != "": params['token'] = self._token res = self._do_get(url, params) qResults = [] for r in res['results']: qResults.append(common.Feature(r)) print 'stop' return qResults
def create_feature_template(self): """creates a feature template""" fields = self.fields feat_schema = {} att = {} for fld in fields: self._globalIdField if not fld['name'] == self._objectIdField and not fld['name'] == self._globalIdField: att[fld['name']] = '' feat_schema['attributes'] = att feat_schema['geometry'] = '' return common.Feature(feat_schema)
def getFeatureDynamicLayer(self, oid, dynamicLayer, returnZ=False, returnM=False): """ The feature resource represents a single feature in a dynamic layer in a map service """ url = self._url + "/dynamicLayer/%s" % oid params = { "f": "json", "returnZ": returnZ, "returnM" : returnM, "layer": { "id": 101, "source" : dynamicLayer.asDictionary } } return common.Feature( json_string=self._do_get(url=url, param_dict=params) )
def query(self, where="1=1", out_fields="*", timeFilter=None, geometryFilter=None, returnGeometry=True, returnIDsOnly=False, returnCountOnly=False, returnFeatureClass=False, out_fc=None): """ queries a feature service based on a sql statement Inputs: where - the selection sql statement out_fields - the attribute fields to return timeFilter - a TimeFilter object where either the start time or start and end time are defined to limit the search results for a given time. The values in the timeFilter should be as UTC timestampes in milliseconds. No checking occurs to see if they are in the right format. geometryFilter - a GeometryFilter object to parse down a given query by another spatial dataset. returnGeometry - true means a geometry will be returned, else just the attributes returnIDsOnly - false is default. True means only OBJECTIDs will be returned returnCountOnly - if True, then an integer is returned only based on the sql statement returnFeatureClass - Default False. If true, query will be returned as feature class out_fc - only valid if returnFeatureClass is set to True. Output location of query. Output: A list of Feature Objects (default) or a path to the output featureclass if returnFeatureClass is set to True. """ params = { "f": "json", "where": where, "outFields": out_fields, "returnGeometry": returnGeometry, "returnIdsOnly": returnIDsOnly, "returnCountOnly": returnCountOnly, } if not self._token is None: params["token"] = self._token if not timeFilter is None and \ isinstance(timeFilter, filters.TimeFilter): params['time'] = timeFilter.filter if not geometryFilter is None and \ isinstance(geometryFilter, filters.GeometryFilter): gf = geometryFilter.filter params['geometry'] = gf['geometry'] params['geometryType'] = gf['geometryType'] params['spatialRelationship'] = gf['spatialRel'] params['inSR'] = gf['inSR'] fURL = self._url + "/query" results = self._do_get(fURL, params) if not returnCountOnly and not returnIDsOnly: if returnFeatureClass: json_text = json.dumps(results) temp = common.scratchFolder() + os.sep + uuid.uuid4().get_hex( ) + ".json" with open(temp, 'wb') as writer: writer.write(json_text) writer.flush() del writer fc = common.json_to_featureclass(json_file=temp, out_fc=out_fc) os.remove(temp) return fc else: feats = [] for res in results['features']: feats.append(common.Feature(res)) return feats else: return results return