Пример #1
0
 def _getObjectIdField(self):
     """ sets the object id field for the feature service """
     params = {"f": "json", "token": self._token}
     fsURL = self._url + "?" + urllib.urlencode(params)
     result = urllib.urlopen(fsURL).read()
     json_data = unicode_convert(json.loads(result)["objectIdField"])
     self._objectIdField = json_data
Пример #2
0
 def _do_get(self, url, param_dict, header={}):
         """ performs a get operation """
         url = url + "?%s" % urllib.urlencode(param_dict)
         request = urllib2.Request(url, headers=header)
         result = urllib2.urlopen(request).read()
         jres = json.loads(result)
         return unicode_convert(jres)
Пример #3
0
 def _do_get(self, url, param_dict, header={}):
     """ performs a get operation """
     url = url + "?%s" % urllib.urlencode(param_dict)
     request = urllib2.Request(url, headers=header)
     result = urllib2.urlopen(request).read()
     jres = json.loads(result)
     return unicode_convert(jres)
Пример #4
0
 def _getGeometryType(self):
     """ if the value is None for _geometryType, this will set it from the
         serivce
     """
     params = {"f": "json", "token": self._token}
     fsURL = self._url + "?" + urllib.urlencode(params)
     result = urllib.urlopen(fsURL).read()
     json_data = unicode_convert(json.loads(result)["geometryType"])
     self._geometryType = json_data
Пример #5
0
 def _getSpatialReference(self):
     """ sets the feature service spatial reference """
     #"spatialReference"
     fURL = os.path.dirname(self._url)
     params = {"f": "json", "token": self._token}
     fsURL = fURL + "?" + urllib.urlencode(params)
     result = urllib.urlopen(fsURL).read()
     json_data = json.loads(result)
     self._spatialReference = unicode_convert(json_data["spatialReference"])
Пример #6
0
 def _getObjectIdField(self):
     """ sets the object id field for the feature service """
     params = {"f" : "json",
               "token" : self._token
               }
     fsURL = self._url + "?" + urllib.urlencode(params)
     result = urllib.urlopen(fsURL).read()
     json_data = unicode_convert(json.loads(result)["objectIdField"])
     self._objectIdField = json_data
Пример #7
0
 def _getFields(self):
     """ returns the feature class's fields """
     params = {"f": "json",
             "where": "1=1",
             "token": self._token,
             "outFields": "*"}
     fURL = self._url + "?" + urllib.urlencode(params)#/query
     result = urllib.urlopen(fURL).read()
     jobj = unicode_convert(json.loads(result))
     return jobj['fields']
Пример #8
0
 def _getGeometryType(self):
     """ if the value is None for _geometryType, this will set it from the
         serivce
     """
     params = {"f" : "json",
               "token" : self._token
               }
     fsURL = self._url + "?" + urllib.urlencode(params)
     result = urllib.urlopen(fsURL).read()
     json_data = unicode_convert(json.loads(result)["geometryType"])
     self._geometryType = json_data
Пример #9
0
 def _getSpatialReference(self):
     """ sets the feature service spatial reference """
     #"spatialReference"
     fURL = os.path.dirname(self._url)
     params = {"f" : "json",
               "token" : self._token
               }
     fsURL = fURL + "?" + urllib.urlencode(params)
     result = urllib.urlopen(fsURL).read()
     json_data = json.loads(result)
     self._spatialReference = unicode_convert(json_data["spatialReference"])
Пример #10
0
 def _getFields(self):
     """ returns the feature class's fields """
     params = {
         "f": "json",
         "where": "1=1",
         "token": self._token,
         "outFields": "*"
     }
     fURL = self._url + "?" + urllib.urlencode(params)  #/query
     result = urllib.urlopen(fURL).read()
     jobj = unicode_convert(json.loads(result))
     return jobj['fields']
Пример #11
0
    def addAttachment(self, oid, file_path):
        """ Adds an attachment to a feature service """
        if self.supportsAttachment == True:
            attachURL = self.url + "/%s/addAttachment" % oid
            obj = {'token': self._token,'f':'json'}
            content = open(file_path, 'rb').read()
            parsed = urlparse.urlparse(attachURL)

            res = self._post_multipart(host=parsed.hostname,
                                       selector=parsed.path,
                                       filename=os.path.basename(file_path),
                                       filetype=mimetypes.guess_type(file_path)[0],
                                       content=content,
                                       fields=obj)
            return unicode_convert(json.loads(res))
        else:
            return "Attachments are not supported for this feature service."
Пример #12
0
    def addAttachment(self, oid, file_path):
        """ Adds an attachment to a feature service """
        if self.supportsAttachment == True:
            attachURL = self.url + "/%s/addAttachment" % oid
            obj = {'token': self._token, 'f': 'json'}
            content = open(file_path, 'rb').read()
            parsed = urlparse.urlparse(attachURL)

            res = self._post_multipart(
                host=parsed.hostname,
                selector=parsed.path,
                filename=os.path.basename(file_path),
                filetype=mimetypes.guess_type(file_path)[0],
                content=content,
                fields=obj)
            return unicode_convert(json.loads(res))
        else:
            return "Attachments are not supported for this feature service."
Пример #13
0
 def query(self, sql="1=1", fields="*", returnShapefile=False, out_fc=None):
     """ queries a feature service based on a sql statement
         Inputs:
            service_url - query URL of the feature service
                          URL should be formatted as http(s)://<base_url/query
                          example: http://sampleserver5.arcgisonline.com/arcgis/rest/services/CommercialDamageAssessment/FeatureServer/0/query
            token - string - sercurity token for service
            sql - string - Query statement
            fields - string - comma seperated string of fields names, * returns all
         Output:
            Dictionary
      """
     params = {"f": "json",
               "where": sql,
               "outFields":fields,
               "token": self._token}
     fURL = self._url + "/query?" + urllib.urlencode(params)
     result = "%s" % urllib.urlopen(fURL).read()
     js = unicode_convert(json.loads(result))
     if returnShapefile:
         return Utilities.dictionary_to_feature_class(js, out_fc)
     return js
Пример #14
0
 def query(self, sql="1=1", fields="*", returnShapefile=False, out_fc=None):
     """ queries a feature service based on a sql statement
         Inputs:
            service_url - query URL of the feature service
                          URL should be formatted as http(s)://<base_url/query
                          example: http://sampleserver5.arcgisonline.com/arcgis/rest/services/CommercialDamageAssessment/FeatureServer/0/query
            token - string - sercurity token for service
            sql - string - Query statement
            fields - string - comma seperated string of fields names, * returns all
         Output:
            Dictionary
      """
     params = {
         "f": "json",
         "where": sql,
         "outFields": fields,
         "token": self._token
     }
     fURL = self._url + "/query?" + urllib.urlencode(params)
     result = "%s" % urllib.urlopen(fURL).read()
     js = unicode_convert(json.loads(result))
     if returnShapefile:
         return Utilities.dictionary_to_feature_class(js, out_fc)
     return js
Пример #15
0
 def _do_post(self, url, param_dict):
     """ performs the POST operation and returns dictionary result """
     request = urllib2.Request(url, urllib.urlencode(param_dict))
     result = urllib2.urlopen(request).read()
     jres = json.loads(result)
     return unicode_convert(jres)
Пример #16
0
 def _do_post(self, url, param_dict):
     """ performs the POST operation and returns dictionary result """
     request = urllib2.Request(url, urllib.urlencode(param_dict))
     result = urllib2.urlopen(request).read()
     jres = json.loads(result)
     return unicode_convert(jres)