idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
244,800 | def _3 ( self ) : boundary = self . boundary buf = BytesIO ( ) textwriter = io . TextIOWrapper ( buf , 'utf8' , newline = '' , write_through = True ) for ( key , value ) in self . form_fields : textwriter . write ( '--{boundary}\r\n' 'Content-Disposition: form-data; name="{key}"\r\n\r\n' '{value}\r\n' . format ( boundary = boundary , key = key , value = value ) ) for ( key , filename , mimetype , filepath ) in self . files : if os . path . isfile ( filepath ) : textwriter . write ( '--{boundary}\r\n' 'Content-Disposition: form-data; name="{key}"; ' 'filename="{filename}"\r\n' 'Content-Type: {content_type}\r\n\r\n' . format ( boundary = boundary , key = key , filename = filename , content_type = mimetype ) ) with open ( filepath , "rb" ) as f : shutil . copyfileobj ( f , buf ) textwriter . write ( '\r\n' ) textwriter . write ( '--{}--\r\n\r\n' . format ( boundary ) ) self . form_data = buf . getvalue ( ) | python 3 method | 312 | 3 |
244,801 | def _get_file_name ( self , contentDisposition , url , ext = ".unknown" ) : if self . PY2 : if contentDisposition is not None : return re . findall ( r'filename[^;=\n]*=(([\'"]).*?\2|[^;\n]*)' , contentDisposition . strip ( ) . replace ( '"' , '' ) ) [ 0 ] [ 0 ] elif os . path . basename ( url ) . find ( '.' ) > - 1 : return os . path . basename ( url ) elif self . PY3 : if contentDisposition is not None : p = re . compile ( r'filename[^;=\n]*=(([\'"]).*?\2|[^;\n]*)' ) return p . findall ( contentDisposition . strip ( ) . replace ( '"' , '' ) ) [ 0 ] [ 0 ] elif os . path . basename ( url ) . find ( '.' ) > - 1 : return os . path . basename ( url ) return "%s.%s" % ( uuid . uuid4 ( ) . get_hex ( ) , ext ) | gets the file name from the header or url if possible | 264 | 11 |
244,802 | def _mainType ( self , resp ) : if self . PY2 : return resp . headers . maintype elif self . PY3 : return resp . headers . get_content_maintype ( ) else : return None | gets the main type from the response object | 49 | 8 |
244,803 | def _chunk ( self , response , size = 4096 ) : method = response . headers . get ( "content-encoding" ) if method == "gzip" : d = zlib . decompressobj ( 16 + zlib . MAX_WBITS ) b = response . read ( size ) while b : data = d . decompress ( b ) yield data b = response . read ( size ) del data else : while True : chunk = response . read ( size ) if not chunk : break yield chunk | downloads a web response in pieces | 109 | 7 |
244,804 | def _asString ( self , value ) : if sys . version_info [ 0 ] == 3 : if isinstance ( value , str ) : return value elif isinstance ( value , bytes ) : return value . decode ( 'utf-8' ) elif sys . version_info [ 0 ] == 2 : return value . encode ( 'ascii' ) | converts the value as a string | 78 | 7 |
244,805 | def machines ( self ) : if self . _resources is None : self . __init ( ) if "machines" in self . _resources : url = self . _url + "/machines" return _machines . Machines ( url , securityHandler = self . _securityHandler , initialize = False , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) else : return None | gets a reference to the machines object | 93 | 7 |
244,806 | def data ( self ) : if self . _resources is None : self . __init ( ) if "data" in self . _resources : url = self . _url + "/data" return _data . Data ( url = url , securityHandler = self . _securityHandler , initialize = True , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) else : return None | returns the reference to the data functions as a class | 89 | 11 |
244,807 | def info ( self ) : if self . _resources is None : self . __init ( ) url = self . _url + "/info" return _info . Info ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) | A read - only resource that returns meta information about the server | 75 | 12 |
244,808 | def clusters ( self ) : if self . _resources is None : self . __init ( ) if "clusters" in self . _resources : url = self . _url + "/clusters" return _clusters . Cluster ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) else : return None | returns the clusters functions if supported in resources | 92 | 9 |
244,809 | def services ( self ) : if self . _resources is None : self . __init ( ) if "services" in self . _resources : url = self . _url + "/services" return _services . Services ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) else : return None | Gets the services object which will provide the ArcGIS Server s admin information about services and folders . | 89 | 21 |
244,810 | def usagereports ( self ) : if self . _resources is None : self . __init ( ) if "usagereports" in self . _resources : url = self . _url + "/usagereports" return _usagereports . UsageReports ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) else : return None | Gets the services object which will provide the ArcGIS Server s admin information about the usagereports . | 94 | 21 |
244,811 | def kml ( self ) : url = self . _url + "/kml" return _kml . KML ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) | returns the kml functions for server | 65 | 8 |
244,812 | def logs ( self ) : if self . _resources is None : self . __init ( ) if "logs" in self . _resources : url = self . _url + "/logs" return _logs . Log ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) else : return None | returns an object to work with the site logs | 92 | 10 |
244,813 | def mode ( self ) : if self . _resources is None : self . __init ( ) if "mode" in self . _resources : url = self . _url + "/mode" return _mode . Mode ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) else : return None | returns an object to work with the site mode | 89 | 10 |
244,814 | def security ( self ) : if self . _resources is None : self . __init ( ) if "security" in self . _resources : url = self . _url + "/security" return _security . Security ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) else : return None | returns an object to work with the site security | 89 | 10 |
244,815 | def system ( self ) : if self . _resources is None : self . __init ( ) if "system" in self . _resources : url = self . _url + "/system" return _system . System ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) else : return None | returns an object to work with the site system | 89 | 10 |
244,816 | def uploads ( self ) : if self . _resources is None : self . __init ( ) if "uploads" in self . _resources : url = self . _url + "/uploads" return _uploads . Uploads ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) else : return None | returns an object to work with the site uploads | 91 | 11 |
244,817 | def getGroupIDs ( self , groupNames , communityInfo = None ) : group_ids = [ ] if communityInfo is None : communityInfo = self . communitySelf if isinstance ( groupNames , list ) : groupNames = map ( str . upper , groupNames ) else : groupNames = groupNames . upper ( ) if 'groups' in communityInfo : for gp in communityInfo [ 'groups' ] : if str ( gp [ 'title' ] ) . upper ( ) in groupNames : group_ids . append ( gp [ 'id' ] ) del communityInfo return group_ids | This function retrieves the group IDs | 125 | 7 |
244,818 | def groups ( self ) : return Groups ( url = "%s/groups" % self . root , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initalize = False ) | returns the group object | 58 | 5 |
244,819 | def group ( self , groupId ) : url = "%s/%s" % ( self . root , groupId ) return Group ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initalize = False ) | gets a group based on it s ID | 70 | 8 |
244,820 | def invite ( self , users , role , expiration = 1440 ) : params = { "f" : "json" , "users" : users , "role" : role , "expiration" : expiration } return self . _post ( url = self . _url + "/invite" , securityHandler = self . _securityHandler , param_dict = params , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | A group administrator can invite users to join their group using the Invite to Group operation . This creates a new user invitation which the users accept or decline . The role of the user and the invitation expiration date can be set in the invitation . A notification is created for the user indicating that they were invited to join the group . Available only to authenticated users . | 99 | 71 |
244,821 | def applications ( self ) : url = self . _url + "/applications" params = { "f" : "json" } res = self . _get ( url = url , param_dict = params , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) items = [ ] if "applications" in res . keys ( ) : for apps in res [ 'applications' ] : items . append ( self . Application ( url = "%s/%s" % ( self . _url , apps [ 'username' ] ) , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) ) return items | returns all the group applications to join | 162 | 8 |
244,822 | def search ( self , q , start = 1 , num = 10 , sortField = "username" , sortOrder = "asc" ) : params = { "f" : "json" , "q" : q , "start" : start , "num" : num , "sortField" : sortField , "sortOrder" : sortOrder } url = self . _url return self . _get ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | The User Search operation searches for users in the portal . The search index is updated whenever users are created updated or deleted . There can be a lag between the time that the user is updated and the time when it s reflected in the search results . The results only contain users that the calling user has permissions to see . Users can control this visibility by changing the access property of their user . | 128 | 77 |
244,823 | def __getUsername ( self ) : if self . _securityHandler is not None and not self . _securityHandler . _username is None : return self . _securityHandler . _username elif self . _securityHandler is not None and hasattr ( self . _securityHandler , "org_url" ) and self . _securityHandler . org_url is not None : from . administration import Administration user = Administration ( url = self . _securityHandler . org_url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) . portals . portalSelf . user return user [ 'username' ] else : from . administration import Administration url = self . _url . lower ( ) . split ( '/content/' ) [ 0 ] user = Administration ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) . portals . portalSelf . user return user [ 'username' ] | tries to parse the user name from various objects | 227 | 10 |
244,824 | def user ( self , username = None ) : if username is None : username = self . __getUsername ( ) parsedUsername = urlparse . quote ( username ) url = self . root + "/%s" % parsedUsername return User ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = False ) | A user resource that represents a registered user in the portal . | 92 | 12 |
244,825 | def userContent ( self ) : replace_start = self . _url . lower ( ) . find ( "/community/" ) len_replace = len ( "/community/" ) url = self . _url . replace ( self . _url [ replace_start : replace_start + len_replace ] , '/content/' ) from . _content import User as UserContent return UserContent ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | allows access into the individual user s content to get at the items owned by the current user | 116 | 18 |
244,826 | def invitations ( self ) : url = "%s/invitations" % self . root return Invitations ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | returns a class to access the current user s invitations | 57 | 11 |
244,827 | def notifications ( self ) : params = { "f" : "json" } url = "%s/notifications" % self . root return Notifications ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | The notifications that are available for the given user . Notifications are events that need the user s attention - application for joining a group administered by the user acceptance of a group membership application and so on . A notification is initially marked as new . The user can mark it as read or delete the notification . | 68 | 60 |
244,828 | def resetPassword ( self , email = True ) : url = self . root + "/reset" params = { "f" : "json" , "email" : email } return self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | resets a users password for an account . The password will be randomly generated and emailed by the system . | 84 | 21 |
244,829 | def expirePassword ( self , hours = "now" ) : params = { "f" : "json" } expiration = - 1 if isinstance ( hours , str ) : if expiration == "now" : expiration = - 1 elif expiration == "never" : expiration = 0 else : expiration = - 1 elif isinstance ( expiration , ( int , long ) ) : dt = datetime . now ( ) + timedelta ( hours = hours ) expiration = local_time_to_online ( dt = dt ) else : expiration = - 1 params [ 'expiration' ] = expiration url = "%s/expirePassword" % self . root return self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | sets a time when a user must reset their password | 187 | 10 |
244,830 | def userInvitations ( self ) : self . __init ( ) items = [ ] for n in self . _userInvitations : if "id" in n : url = "%s/%s" % ( self . root , n [ 'id' ] ) items . append ( self . Invitation ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) ) return items | gets all user invitations | 107 | 4 |
244,831 | def notifications ( self ) : self . __init ( ) items = [ ] for n in self . _notifications : if "id" in n : url = "%s/%s" % ( self . root , n [ 'id' ] ) items . append ( self . Notification ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) ) return items | gets the user s notifications | 99 | 5 |
244,832 | def add ( self , statisticType , onStatisticField , outStatisticFieldName = None ) : val = { "statisticType" : statisticType , "onStatisticField" : onStatisticField , "outStatisticFieldName" : outStatisticFieldName } if outStatisticFieldName is None : del val [ 'outStatisticFieldName' ] self . _array . append ( val ) | Adds the statistics group to the filter . | 89 | 8 |
244,833 | def addFilter ( self , layer_id , where = None , outFields = "*" ) : import copy f = copy . deepcopy ( self . _filterTemplate ) f [ 'layerId' ] = layer_id f [ 'outFields' ] = outFields if where is not None : f [ 'where' ] = where if f not in self . _filter : self . _filter . append ( f ) | adds a layer definition filter | 93 | 6 |
244,834 | def removeFilter ( self , filter_index ) : f = self . _filter [ filter_index ] self . _filter . remove ( f ) | removes a layer filter based on position in filter list | 31 | 11 |
244,835 | def geometry ( self , geometry ) : if isinstance ( geometry , AbstractGeometry ) : self . _geomObject = geometry self . _geomType = geometry . type elif arcpyFound : wkid = None wkt = None if ( hasattr ( geometry , 'spatialReference' ) and geometry . spatialReference is not None ) : if ( hasattr ( geometry . spatialReference , 'factoryCode' ) and geometry . spatialReference . factoryCode is not None ) : wkid = geometry . spatialReference . factoryCode else : wkt = geometry . spatialReference . exportToString ( ) if isinstance ( geometry , arcpy . Polygon ) : self . _geomObject = Polygon ( geometry , wkid = wkid , wkt = wkt ) self . _geomType = "esriGeometryPolygon" elif isinstance ( geometry , arcpy . Point ) : self . _geomObject = Point ( geometry , wkid = wkid , wkt = wkt ) self . _geomType = "esriGeometryPoint" elif isinstance ( geometry , arcpy . Polyline ) : self . _geomObject = Polyline ( geometry , wkid = wkid , wkt = wkt ) self . _geomType = "esriGeometryPolyline" elif isinstance ( geometry , arcpy . Multipoint ) : self . _geomObject = MultiPoint ( geometry , wkid = wkid , wkt = wkt ) self . _geomType = "esriGeometryMultipoint" else : raise AttributeError ( "geometry must be a common.Geometry or arcpy.Geometry type." ) else : raise AttributeError ( "geometry must be a common.Geometry or arcpy.Geometry type." ) | sets the geometry value | 390 | 4 |
244,836 | def layers ( self ) : if self . _layers is None : self . __init ( ) lyrs = [ ] for lyr in self . _layers : url = self . _url + "/%s" % lyr [ 'id' ] lyr [ 'object' ] = MobileServiceLayer ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = False ) return self . _layers | gets the service layers | 109 | 4 |
244,837 | def clusters ( self ) : if self . _clusters is not None : self . __init ( ) Cs = [ ] for c in self . _clusters : url = self . _url + "/%s" % c [ 'clusterName' ] Cs . append ( Cluster ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) ) self . _clusters = Cs return self . _clusters | returns the cluster object for each server | 117 | 8 |
244,838 | def editProtocol ( self , clusterProtocolObj ) : if isinstance ( clusterProtocolObj , ClusterProtocol ) : pass else : raise AttributeError ( "Invalid Input, must be a ClusterProtocal Object" ) url = self . _url + "/editProtocol" params = { "f" : "json" , "tcpClusterPort" : str ( clusterProtocolObj . value [ 'tcpClusterPort' ] ) } return self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | Updates the Cluster Protocol . This will cause the cluster to be restarted with updated protocol configuration . | 145 | 20 |
244,839 | def parameters ( self ) : if self . _parameters is None : self . __init ( ) for param in self . _parameters : if not isinstance ( param [ 'defaultValue' ] , BaseGPObject ) : if param [ 'dataType' ] == "GPFeatureRecordSetLayer" : param [ 'defaultValue' ] = GPFeatureRecordSetLayer . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPString" : param [ 'defaultValue' ] = GPString . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPLong" : param [ 'defaultValue' ] = GPLong . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPDouble" : param [ 'defaultValue' ] = GPDouble . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPDate" : param [ 'defaultValue' ] = GPDate . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPBoolean" : param [ 'defaultValue' ] = GPBoolean . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPDataFile" : param [ 'defaultValue' ] = GPDataFile . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPLinearUnit" : param [ 'defaultValue' ] = GPLinearUnit . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPMultiValue" : param [ 'defaultValue' ] = GPMultiValue . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPRasterData" : param [ 'defaultValue' ] = GPRasterData . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPRasterDataLayer" : param [ 'defaultValue' ] = GPRasterDataLayer . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPRecordSet" : param [ 'defaultValue' ] = GPRecordSet . fromJSON ( json . dumps ( param ) ) return self . _parameters | returns the default parameters | 529 | 5 |
244,840 | def getJob ( self , jobID ) : url = self . _url + "/jobs/%s" % ( jobID ) return GPJob ( url = url , securityHandler = self . _securityHandler , proxy_port = self . _proxy_port , proxy_url = self . _proxy_url ) | returns the results or status of a job | 67 | 9 |
244,841 | def executeTask ( self , inputs , outSR = None , processSR = None , returnZ = False , returnM = False , f = "json" , method = "POST" ) : params = { "f" : f } url = self . _url + "/execute" params = { "f" : "json" } if not outSR is None : params [ 'env:outSR' ] = outSR if not processSR is None : params [ 'end:processSR' ] = processSR params [ 'returnZ' ] = returnZ params [ 'returnM' ] = returnM for p in inputs : if isinstance ( p , BaseGPObject ) : params [ p . paramName ] = p . value del p if method . lower ( ) == "post" : return self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) else : return self . _get ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | performs the execute task method | 265 | 6 |
244,842 | def _get_json ( self , urlpart ) : url = self . _url + "/%s" % urlpart params = { "f" : "json" , } return self . _get ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . proxy_port ) | gets the result object dictionary | 84 | 5 |
244,843 | def results ( self ) : self . __init ( ) for k , v in self . _results . items ( ) : param = self . _get_json ( v [ 'paramUrl' ] ) if param [ 'dataType' ] == "GPFeatureRecordSetLayer" : self . _results [ k ] = GPFeatureRecordSetLayer . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] . lower ( ) . find ( 'gpmultivalue' ) > - 1 : self . _results [ k ] = GPMultiValue . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPString" : self . _results [ k ] = GPString . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPLong" : self . _results [ k ] = GPLong . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPDouble" : self . _results [ k ] = GPDouble . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPDate" : self . _results [ k ] = GPDate . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPBoolean" : self . _results [ k ] = GPBoolean . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPDataFile" : self . _results [ k ] = GPDataFile . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPLinearUnit" : self . _results [ k ] = GPLinearUnit . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPMultiValue" : self . _results [ k ] = GPMultiValue . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPRasterData" : self . _results [ k ] = GPRasterData . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPRasterDataLayer" : self . _results [ k ] = GPRasterDataLayer . fromJSON ( json . dumps ( param ) ) elif param [ 'dataType' ] == "GPRecordSet" : self . _results [ k ] = GPRecordSet . fromJSON ( json . dumps ( param ) ) return self . _results | returns the results | 575 | 4 |
244,844 | def getParameterValue ( self , parameterName ) : if self . _results is None : self . __init ( ) parameter = self . _results [ parameterName ] return parameter | gets a parameter value | 37 | 4 |
244,845 | def parentLayer ( self ) : if self . _parentLayer is None : from . . agol . services import FeatureService self . __init ( ) url = os . path . dirname ( self . _url ) self . _parentLayer = FeatureService ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) return self . _parentLayer | returns information about the parent | 96 | 6 |
244,846 | def _chunks ( self , l , n ) : l . sort ( ) newn = int ( 1.0 * len ( l ) / n + 0.5 ) for i in range ( 0 , n - 1 ) : yield l [ i * newn : i * newn + newn ] yield l [ n * newn - newn : ] | Yield n successive chunks from a list l . | 77 | 10 |
244,847 | def calculate ( self , where , calcExpression , sqlFormat = "standard" ) : url = self . _url + "/calculate" params = { "f" : "json" , "where" : where , } if isinstance ( calcExpression , dict ) : params [ "calcExpression" ] = json . dumps ( [ calcExpression ] , default = _date_handler ) elif isinstance ( calcExpression , list ) : params [ "calcExpression" ] = json . dumps ( calcExpression , default = _date_handler ) if sqlFormat . lower ( ) in [ 'native' , 'standard' ] : params [ 'sqlFormat' ] = sqlFormat . lower ( ) else : params [ 'sqlFormat' ] = "standard" return self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_port = self . _proxy_port , proxy_url = self . _proxy_url ) | The calculate operation is performed on a feature service layer resource . It updates the values of one or more fields in an existing feature service layer based on SQL expressions or scalar values . The calculate operation can only be used if the supportsCalculate property of the layer is true . Neither the Shape field nor system fields can be updated using calculate . System fields include ObjectId and GlobalId . See Calculate a field for more information on supported expressions | 216 | 89 |
244,848 | def validateSQL ( self , sql , sqlType = "where" ) : url = self . _url + "/validateSQL" if not sqlType . lower ( ) in [ 'where' , 'expression' , 'statement' ] : raise Exception ( "Invalid Input for sqlType: %s" % sqlType ) params = { "f" : "json" , "sql" : sql , "sqlType" : sqlType } return self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | The validateSQL operation validates an SQL - 92 expression or WHERE clause . The validateSQL operation ensures that an SQL - 92 expression such as one written by a user through a user interface is correct before performing another operation that uses the expression . For example validateSQL can be used to validate information that is subsequently passed in as part of the where parameter of the calculate operation . validateSQL also prevents SQL injection . In addition all table and field names used in the SQL expression or WHERE clause are validated to ensure they are valid tables and fields . | 140 | 107 |
244,849 | def asDictionary ( self ) : template = { "type" : self . _type , "mapLayerId" : self . _mapLayerId } if not self . _gdbVersion is None and self . _gdbVersion != "" : template [ 'gdbVersion' ] = self . _gdbVersion return template | converts the object to a dictionary | 70 | 7 |
244,850 | def asDictionary ( self ) : template = { "type" : "dataLayer" , "dataSource" : self . _dataSource } if not self . _fields is None : template [ 'fields' ] = self . _fields return template | returns the value as a dictionary | 53 | 7 |
244,851 | def dataSource ( self , value ) : if isinstance ( value , DataSource ) : self . _dataSource = value else : raise TypeError ( "value must be a DataSource object" ) | sets the datasource object | 42 | 5 |
244,852 | def fields ( self , value ) : if type ( value ) is list : self . _fields = value else : raise TypeError ( "Input must be a list" ) | sets the fields variable | 36 | 4 |
244,853 | def addCodedValue ( self , name , code ) : i = { "name" : name , "code" : code } if i not in self . _codedValues : self . _codedValues . append ( i ) | adds a coded value to the domain | 48 | 8 |
244,854 | def removeCodedValue ( self , name ) : for i in self . _codedValues : if i [ 'name' ] == name : self . _codedValues . remove ( i ) return True return False | removes a codedValue by name | 44 | 7 |
244,855 | def value ( self ) : return { "type" : self . _type , "name" : self . _name , "range" : [ self . _rangeMin , self . _rangeMax ] } | gets the value as a dictionary | 44 | 6 |
244,856 | def measure ( self , fromGeometry , toGeometry , measureOperation , geometryType = "esriGeometryPoint" , pixelSize = None , mosaicRule = None , linearUnit = None , angularUnit = None , areaUnit = None ) : url = self . _url + "/measure" params = { "f" : "json" , "fromGeometry" : fromGeometry , "toGeometry" : toGeometry , "geometryType" : geometryType , "measureOperation" : measureOperation } if not pixelSize is None : params [ "pixelSize" ] = pixelSize if not mosaicRule is None : params [ "mosaicRule" ] = mosaicRule if not linearUnit is None : params [ "linearUnit" ] = linearUnit if not angularUnit is None : params [ "angularUnit" ] = angularUnit if not areaUnit is None : params [ "areaUnit" ] = areaUnit return self . _get ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | The measure operation is performed on an image service resource . It lets a user measure distance direction area perimeter and height from an image service . The result of this operation includes the name of the raster dataset being used sensor name and measured values . | 247 | 48 |
244,857 | def computeStatisticsHistograms ( self , geometry , geometryType , mosaicRule = None , renderingRule = None , pixelSize = None ) : url = self . _url + "/computeStatisticsHistograms" params = { "f" : "json" , "geometry" : geometry , "geometryType" : geometryType } if not mosaicRule is None : params [ "mosaicRule" ] = mosaicRule if not renderingRule is None : params [ "renderingRule" ] = renderingRule if not pixelSize is None : params [ "pixelSize" ] = pixelSize return self . _get ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | The computeStatisticsHistograms operation is performed on an image service resource . This operation is supported by any image service published with mosaic datasets or a raster dataset . The result of this operation contains both statistics and histograms computed from the given extent . | 171 | 49 |
244,858 | def uploadByParts ( self , registerID , filePath , commit = True ) : url = self . _url + "/%s/uploadPart" % registerID params = { "f" : "json" } with open ( filePath , 'rb' ) as f : mm = mmap . mmap ( f . fileno ( ) , 0 , access = mmap . ACCESS_READ ) size = 1000000 steps = int ( os . fstat ( f . fileno ( ) ) . st_size / size ) if os . fstat ( f . fileno ( ) ) . st_size % size > 0 : steps += 1 for i in range ( steps ) : files = { } tempFile = os . path . join ( os . environ [ 'TEMP' ] , "split.part%s" % i ) if os . path . isfile ( tempFile ) : os . remove ( tempFile ) with open ( tempFile , 'wb' ) as writer : writer . write ( mm . read ( size ) ) writer . flush ( ) writer . close ( ) del writer files [ 'file' ] = tempFile params [ 'partNum' ] = i + 1 res = self . _post ( url = url , param_dict = params , files = files , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) os . remove ( tempFile ) del files del mm return self . commit ( registerID ) | loads the data by small parts . If commit is set to true then parts will be merged together . If commit is false the function will return the registerID so a manual commit can occur . | 326 | 38 |
244,859 | def uploads ( self ) : if self . syncEnabled == True : return Uploads ( url = self . _url + "/uploads" , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) return None | returns the class to perform the upload function . it will only return the uploads class if syncEnabled is True . | 63 | 24 |
244,860 | def administration ( self ) : url = self . _url res = search ( "/rest/" , url ) . span ( ) addText = "admin/" part1 = url [ : res [ 1 ] ] part2 = url [ res [ 1 ] : ] adminURL = "%s%s%s" % ( part1 , addText , part2 ) res = AdminFeatureService ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = False ) return res | returns the hostservice object to manage the back - end functions | 122 | 13 |
244,861 | def replicas ( self ) : params = { "f" : "json" , } url = self . _url + "/replicas" return self . _get ( url , params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | returns all the replicas for a feature service | 71 | 10 |
244,862 | def createReplica ( self , replicaName , layers , layerQueries = None , geometryFilter = None , replicaSR = None , transportType = "esriTransportTypeUrl" , returnAttachments = False , returnAttachmentsDatabyURL = False , async = False , attachmentsSyncDirection = "none" , syncModel = "none" , dataFormat = "json" , replicaOptions = None , wait = False , out_path = None ) : if self . syncEnabled == False and "Extract" not in self . capabilities : return None url = self . _url + "/createReplica" dataformat = [ "filegdb" , "json" , "sqlite" , "shapefile" ] params = { "f" : "json" , "replicaName" : replicaName , "returnAttachments" : returnAttachments , "returnAttachmentsDatabyURL" : returnAttachmentsDatabyURL , "attachmentsSyncDirection" : attachmentsSyncDirection , "async" : async , "syncModel" : syncModel , "layers" : layers } if dataFormat . lower ( ) in dataformat : params [ 'dataFormat' ] = dataFormat . lower ( ) else : raise Exception ( "Invalid dataFormat" ) if layerQueries is not None : params [ 'layerQueries' ] = layerQueries if geometryFilter is not None and isinstance ( geometryFilter , GeometryFilter ) : params . update ( geometryFilter . filter ) if replicaSR is not None : params [ 'replicaSR' ] = replicaSR if replicaOptions is not None : params [ 'replicaOptions' ] = replicaOptions if transportType is not None : params [ 'transportType' ] = transportType if async : if wait : exportJob = self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) status = self . replicaStatus ( url = exportJob [ 'statusUrl' ] ) while status [ 'status' ] . lower ( ) != "completed" : status = self . replicaStatus ( url = exportJob [ 'statusUrl' ] ) if status [ 'status' ] . lower ( ) == "failed" : return status res = status else : res = self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) else : res = self . _post ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) if out_path is not None and os . path . isdir ( out_path ) : dlURL = None if 'resultUrl' in res : dlURL = res [ "resultUrl" ] elif 'responseUrl' in res : dlURL = res [ "responseUrl" ] elif 'URL' in res : dlURL = res [ "URL" ] if dlURL is not None : return self . _get ( url = dlURL , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , out_folder = out_path ) else : return res elif res is not None : return res return None | The createReplica operation is performed on a feature service resource . This operation creates the replica between the feature service and a client based on a client - supplied replica definition . It requires the Sync capability . See Sync overview for more information on sync . The response for createReplica includes replicaID server generation number and data similar to the response from the feature service query operation . The createReplica operation returns a response of type esriReplicaResponseTypeData as the response has data for the layers in the replica . If the operation is called to register existing data by using replicaOptions the response type will be esriReplicaResponseTypeInfo and the response will not contain data for the layers in the replica . | 757 | 142 |
244,863 | def replicaStatus ( self , url ) : params = { "f" : "json" } url = url + "/status" return self . _get ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_port = self . _proxy_port , proxy_url = self . _proxy_url ) | gets the replica status when exported async set to True | 74 | 10 |
244,864 | def listAttachments ( self , oid ) : url = self . _url + "/%s/attachments" % oid params = { "f" : "json" } return self . _get ( url , params , securityHandler = self . _securityHandler , proxy_port = self . _proxy_port , proxy_url = self . _proxy_url ) | list attachements for a given OBJECT ID | 80 | 10 |
244,865 | def getAttachment ( self , oid , attachment_id , out_folder = None ) : attachments = self . listAttachments ( oid = oid ) if "attachmentInfos" in attachments : for attachment in attachments [ 'attachmentInfos' ] : if "id" in attachment and attachment [ 'id' ] == attachment_id : url = self . _url + "/%s/attachments/%s" % ( oid , attachment_id ) return self . _get ( url = url , param_dict = { "f" : 'json' } , securityHandler = self . _securityHandler , out_folder = out_folder , file_name = attachment [ 'name' ] ) return None | downloads a feature s attachment . | 156 | 7 |
244,866 | def create_fc_template ( self , out_path , out_name ) : fields = self . fields objectIdField = self . objectIdField geomType = self . geometryType wkid = self . parentLayer . spatialReference [ 'wkid' ] return create_feature_class ( out_path , out_name , geomType , wkid , fields , objectIdField ) | creates a featureclass template on local disk | 84 | 9 |
244,867 | def create_feature_template ( self ) : 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 Feature ( feat_schema ) | creates a feature template | 115 | 5 |
244,868 | def spatialReference ( self ) : if self . _wkid == None and self . _wkt is not None : return { "wkt" : self . _wkt } else : return { "wkid" : self . _wkid } | returns the geometry spatial reference | 53 | 6 |
244,869 | def asJSON ( self ) : value = self . _json if value is None : value = json . dumps ( self . asDictionary , default = _date_handler ) self . _json = value return self . _json | returns a geometry as JSON | 48 | 6 |
244,870 | def asArcPyObject ( self ) : if arcpyFound == False : raise Exception ( "ArcPy is required to use this function" ) return arcpy . AsShape ( self . asDictionary , True ) | returns the Point as an ESRI arcpy . Point object | 45 | 13 |
244,871 | def X ( self , value ) : if isinstance ( value , ( int , float , long , types . NoneType ) ) : self . _x = value | sets the X coordinate | 34 | 4 |
244,872 | def Y ( self , value ) : if isinstance ( value , ( int , float , long , types . NoneType ) ) : self . _y = value | sets the Y coordinate | 34 | 4 |
244,873 | def Z ( self , value ) : if isinstance ( value , ( int , float , long , types . NoneType ) ) : self . _z = value | sets the Z coordinate | 34 | 4 |
244,874 | def wkid ( self , value ) : if isinstance ( value , ( int , long ) ) : self . _wkid = value | sets the wkid | 29 | 4 |
244,875 | def asDictionary ( self ) : template = { "xmin" : self . _xmin , "ymin" : self . _ymin , "xmax" : self . _xmax , "ymax" : self . _ymax , "spatialReference" : self . spatialReference } if self . _zmax is not None and self . _zmin is not None : template [ 'zmin' ] = self . _zmin template [ 'zmax' ] = self . _zmax if self . _mmin is not None and self . _mmax is not None : template [ 'mmax' ] = self . _mmax template [ 'mmin' ] = self . _mmin return template | returns the envelope as a dictionary | 158 | 7 |
244,876 | def asArcPyObject ( self ) : env = self . asDictionary ring = [ [ Point ( env [ 'xmin' ] , env [ 'ymin' ] , self . _wkid ) , Point ( env [ 'xmax' ] , env [ 'ymin' ] , self . _wkid ) , Point ( env [ 'xmax' ] , env [ 'ymax' ] , self . _wkid ) , Point ( env [ 'xmin' ] , env [ 'ymax' ] , self . _wkid ) ] ] return Polygon ( rings = ring , wkid = self . _wkid , wkt = self . _wkid , hasZ = False , hasM = False ) . asArcPyObject | returns the Envelope as an ESRI arcpy . Polygon object | 162 | 16 |
244,877 | def _process_response ( self , resp , out_folder = None ) : CHUNK = 4056 maintype = self . _mainType ( resp ) contentDisposition = resp . headers . get ( 'content-disposition' ) contentEncoding = resp . headers . get ( 'content-encoding' ) contentType = resp . headers . get ( 'content-type' ) contentLength = resp . headers . get ( 'content-length' ) if maintype . lower ( ) in ( 'image' , 'application/x-zip-compressed' ) or contentType == 'application/x-zip-compressed' or ( contentDisposition is not None and contentDisposition . lower ( ) . find ( 'attachment;' ) > - 1 ) : fname = self . _get_file_name ( contentDisposition = contentDisposition , url = resp . geturl ( ) ) if out_folder is None : out_folder = tempfile . gettempdir ( ) if contentLength is not None : max_length = int ( contentLength ) if max_length < CHUNK : CHUNK = max_length file_name = os . path . join ( out_folder , fname ) with open ( file_name , 'wb' ) as writer : for data in self . _chunk ( response = resp ) : writer . write ( data ) del data del writer return file_name else : read = "" for data in self . _chunk ( response = resp , size = 4096 ) : if self . PY3 == True : read += data . decode ( 'utf-8' ) else : read += data del data try : return json . loads ( read . strip ( ) ) except : return read return None | processes the response object | 375 | 5 |
244,878 | def addUsersToRole ( self , rolename , users ) : params = { "f" : "json" , "rolename" : rolename , "users" : users } rURL = self . _url + "/roles/addUsersToRole" return self . _post ( url = rURL , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | Assigns a role to multiple users | 106 | 8 |
244,879 | def serverProperties ( self ) : return ServerProperties ( url = self . _url + "/properties" , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) | gets the server properties for the site as an object | 59 | 10 |
244,880 | def serverDirectories ( self ) : directs = [ ] url = self . _url + "/directories" params = { "f" : "json" } res = self . _get ( url = url , param_dict = params , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) for direct in res [ 'directories' ] : directs . append ( ServerDirectory ( url = url + "/%s" % direct [ "name" ] , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) ) return directs | returns the server directory object in a list | 154 | 9 |
244,881 | def Jobs ( self ) : url = self . _url + "/jobs" return Jobs ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port , initialize = True ) | get the Jobs object | 58 | 4 |
244,882 | def configurationStore ( self ) : url = self . _url + "/configstore" return ConfigurationStore ( url = url , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) | returns the ConfigurationStore object for this site | 57 | 9 |
244,883 | def EnableEditingOnService ( self , url , definition = None ) : adminFS = AdminFeatureService ( url = url , securityHandler = self . _securityHandler ) if definition is None : definition = collections . OrderedDict ( ) definition [ 'hasStaticData' ] = False definition [ 'allowGeometryUpdates' ] = True definition [ 'editorTrackingInfo' ] = { } definition [ 'editorTrackingInfo' ] [ 'enableEditorTracking' ] = False definition [ 'editorTrackingInfo' ] [ 'enableOwnershipAccessControl' ] = False definition [ 'editorTrackingInfo' ] [ 'allowOthersToUpdate' ] = True definition [ 'editorTrackingInfo' ] [ 'allowOthersToDelete' ] = True definition [ 'capabilities' ] = "Query,Editing,Create,Update,Delete" existingDef = { } existingDef [ 'capabilities' ] = adminFS . capabilities existingDef [ 'allowGeometryUpdates' ] = adminFS . allowGeometryUpdates enableResults = adminFS . updateDefinition ( json_dict = definition ) if 'error' in enableResults : return enableResults [ 'error' ] adminFS = None del adminFS print ( enableResults ) return existingDef | Enables editing capabilities on a feature service . | 266 | 9 |
244,884 | def enableSync ( self , url , definition = None ) : adminFS = AdminFeatureService ( url = url , securityHandler = self . _securityHandler ) cap = str ( adminFS . capabilities ) existingDef = { } enableResults = 'skipped' if 'Sync' in cap : return "Sync is already enabled" else : capItems = cap . split ( ',' ) capItems . append ( 'Sync' ) existingDef [ 'capabilities' ] = ',' . join ( capItems ) enableResults = adminFS . updateDefinition ( json_dict = existingDef ) if 'error' in enableResults : return enableResults [ 'error' ] adminFS = None del adminFS return enableResults | Enables Sync capability for an AGOL feature service . | 148 | 11 |
244,885 | def GetFeatureService ( self , itemId , returnURLOnly = False ) : admin = None item = None try : admin = arcrest . manageorg . Administration ( securityHandler = self . _securityHandler ) if self . _securityHandler . valid == False : self . _valid = self . _securityHandler . valid self . _message = self . _securityHandler . message return None item = admin . content . getItem ( itemId = itemId ) if item . type == "Feature Service" : if returnURLOnly : return item . url else : fs = arcrest . agol . FeatureService ( url = item . url , securityHandler = self . _securityHandler ) if fs . layers is None or len ( fs . layers ) == 0 : fs = arcrest . ags . FeatureService ( url = item . url ) return fs return None except : line , filename , synerror = trace ( ) raise common . ArcRestHelperError ( { "function" : "GetFeatureService" , "line" : line , "filename" : filename , "synerror" : synerror , } ) finally : admin = None item = None del item del admin gc . collect ( ) | Obtains a feature service by item ID . | 254 | 9 |
244,886 | def GetLayerFromFeatureServiceByURL ( self , url , layerName = "" , returnURLOnly = False ) : fs = None try : fs = arcrest . agol . FeatureService ( url = url , securityHandler = self . _securityHandler ) return self . GetLayerFromFeatureService ( fs = fs , layerName = layerName , returnURLOnly = returnURLOnly ) except : line , filename , synerror = trace ( ) raise common . ArcRestHelperError ( { "function" : "GetLayerFromFeatureServiceByURL" , "line" : line , "filename" : filename , "synerror" : synerror , } ) finally : fs = None del fs gc . collect ( ) | Obtains a layer from a feature service by URL reference . | 154 | 12 |
244,887 | def GetLayerFromFeatureService ( self , fs , layerName = "" , returnURLOnly = False ) : layers = None table = None layer = None sublayer = None try : layers = fs . layers if ( layers is None or len ( layers ) == 0 ) and fs . url is not None : fs = arcrest . ags . FeatureService ( url = fs . url ) layers = fs . layers if layers is not None : for layer in layers : if layer . name == layerName : if returnURLOnly : return fs . url + '/' + str ( layer . id ) else : return layer elif not layer . subLayers is None : for sublayer in layer . subLayers : if sublayer == layerName : return sublayer if fs . tables is not None : for table in fs . tables : if table . name == layerName : if returnURLOnly : return fs . url + '/' + str ( layer . id ) else : return table return None except : line , filename , synerror = trace ( ) raise common . ArcRestHelperError ( { "function" : "GetLayerFromFeatureService" , "line" : line , "filename" : filename , "synerror" : synerror , } ) finally : layers = None table = None layer = None sublayer = None del layers del table del layer del sublayer gc . collect ( ) | Obtains a layer from a feature service by feature service reference . | 295 | 13 |
244,888 | def DeleteFeaturesFromFeatureLayer ( self , url , sql , chunksize = 0 ) : fl = None try : fl = FeatureLayer ( url = url , securityHandler = self . _securityHandler ) totalDeleted = 0 if chunksize > 0 : qRes = fl . query ( where = sql , returnIDsOnly = True ) if 'error' in qRes : print ( qRes ) return qRes elif 'objectIds' in qRes : oids = qRes [ 'objectIds' ] total = len ( oids ) if total == 0 : return { 'success' : True , 'message' : "No features matched the query" } i = 0 print ( "%s features to be deleted" % total ) while ( i <= len ( oids ) ) : oidsDelete = ',' . join ( str ( e ) for e in oids [ i : i + chunksize ] ) if oidsDelete == '' : continue else : results = fl . deleteFeatures ( objectIds = oidsDelete ) if 'deleteResults' in results : totalDeleted += len ( results [ 'deleteResults' ] ) print ( "%s%% Completed: %s/%s " % ( int ( totalDeleted / float ( total ) * 100 ) , totalDeleted , total ) ) i += chunksize else : print ( results ) return { 'success' : True , 'message' : "%s deleted" % totalDeleted } qRes = fl . query ( where = sql , returnIDsOnly = True ) if 'objectIds' in qRes : oids = qRes [ 'objectIds' ] if len ( oids ) > 0 : print ( "%s features to be deleted" % len ( oids ) ) results = fl . deleteFeatures ( where = sql ) if 'deleteResults' in results : totalDeleted += len ( results [ 'deleteResults' ] ) return { 'success' : True , 'message' : "%s deleted" % totalDeleted } else : return results return { 'success' : True , 'message' : "%s deleted" % totalDeleted } else : print ( qRes ) else : results = fl . deleteFeatures ( where = sql ) if results is not None : if 'deleteResults' in results : return { 'success' : True , 'message' : totalDeleted + len ( results [ 'deleteResults' ] ) } else : return results except : line , filename , synerror = trace ( ) raise common . ArcRestHelperError ( { "function" : "DeleteFeaturesFromFeatureLayer" , "line" : line , "filename" : filename , "synerror" : synerror , } ) finally : fl = None del fl gc . collect ( ) | Removes features from a hosted feature service layer by SQL query . | 587 | 13 |
244,889 | def QueryAllFeatures ( self , url = None , where = "1=1" , out_fields = "*" , timeFilter = None , geometryFilter = None , returnFeatureClass = False , out_fc = None , outSR = None , chunksize = 1000 , printIndent = "" ) : if ( url is None ) : return fl = None try : fl = FeatureLayer ( url = url , securityHandler = self . _securityHandler ) qRes = fl . query ( where = where , returnIDsOnly = True , timeFilter = timeFilter , geometryFilter = geometryFilter ) if 'error' in qRes : print ( printIndent + qRes ) return [ ] elif 'objectIds' in qRes : oids = qRes [ 'objectIds' ] total = len ( oids ) if total == 0 : return fl . query ( where = where , returnGeometry = True , out_fields = out_fields , timeFilter = timeFilter , geometryFilter = geometryFilter , outSR = outSR ) print ( printIndent + "%s features to be downloaded" % total ) chunksize = min ( chunksize , fl . maxRecordCount ) combinedResults = None totalQueried = 0 for chunk in chunklist ( l = oids , n = chunksize ) : oidsQuery = "," . join ( map ( str , chunk ) ) if not oidsQuery : continue else : results = fl . query ( objectIds = oidsQuery , returnGeometry = True , out_fields = out_fields , timeFilter = timeFilter , geometryFilter = geometryFilter , outSR = outSR ) if isinstance ( results , FeatureSet ) : if combinedResults is None : combinedResults = results else : for feature in results . features : combinedResults . features . append ( feature ) totalQueried += len ( results . features ) print ( printIndent + "{:.0%} Completed: {}/{}" . format ( totalQueried / float ( total ) , totalQueried , total ) ) else : print ( printIndent + results ) if returnFeatureClass == True : return combinedResults . save ( * os . path . split ( out_fc ) ) else : return combinedResults else : print ( printIndent + qRes ) except : line , filename , synerror = trace ( ) raise common . ArcRestHelperError ( { "function" : "QueryAllFeatures" , "line" : line , "filename" : filename , "synerror" : synerror , } ) finally : fl = None del fl gc . collect ( ) | Performs an SQL query against a hosted feature service layer and returns all features regardless of service limit . | 558 | 20 |
244,890 | def contributionStatus ( self ) : import time url = "%s/contributors/%s/activeContribution" % ( self . root , quote ( self . contributorUID ) ) params = { "agolUserToken" : self . _agolSH . token , "f" : "json" } res = self . _get ( url = url , param_dict = params , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) if 'Status' in res and res [ 'Status' ] == 'start' : return True return False | gets the contribution status of a user | 127 | 7 |
244,891 | def user ( self ) : if self . _user is None : url = "%s/users/%s" % ( self . root , self . _username ) self . _user = CMPUser ( url = url , securityHandler = self . _securityHandler , proxy_port = self . _proxy_port , proxy_url = self . _proxy_url , initialize = False ) return self . _user | gets the user properties | 88 | 4 |
244,892 | def metadataContributer ( self ) : if self . _metaFL is None : fl = FeatureService ( url = self . _metadataURL , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port ) self . _metaFS = fl return self . _metaFS | gets the metadata featurelayer object | 65 | 6 |
244,893 | def set_value ( self , field_name , value ) : if field_name in self . fields : if not value is None : self . _dict [ 'attributes' ] [ field_name ] = _unicode_convert ( value ) else : pass elif field_name . upper ( ) in [ 'SHAPE' , 'SHAPE@' , "GEOMETRY" ] : if isinstance ( value , dict ) : if 'geometry' in value : self . _dict [ 'geometry' ] = value [ 'geometry' ] elif any ( k in value . keys ( ) for k in [ 'x' , 'y' , 'points' , 'paths' , 'rings' , 'spatialReference' ] ) : self . _dict [ 'geometry' ] = value elif isinstance ( value , AbstractGeometry ) : self . _dict [ 'geometry' ] = value . asDictionary elif arcpyFound : if isinstance ( value , arcpy . Geometry ) and value . type == self . geometryType : self . _dict [ 'geometry' ] = json . loads ( value . JSON ) self . _geom = None self . _geom = self . geometry else : return False self . _json = json . dumps ( self . _dict , default = _date_handler ) return True | sets an attribute value for a given field name | 296 | 9 |
244,894 | def get_value ( self , field_name ) : if field_name in self . fields : return self . _dict [ 'attributes' ] [ field_name ] elif field_name . upper ( ) in [ 'SHAPE' , 'SHAPE@' , "GEOMETRY" ] : return self . _dict [ 'geometry' ] return None | returns a value for a given field name | 80 | 9 |
244,895 | def asDictionary ( self ) : feat_dict = { } if self . _geom is not None : if 'feature' in self . _dict : feat_dict [ 'geometry' ] = self . _dict [ 'feature' ] [ 'geometry' ] elif 'geometry' in self . _dict : feat_dict [ 'geometry' ] = self . _dict [ 'geometry' ] if 'feature' in self . _dict : feat_dict [ 'attributes' ] = self . _dict [ 'feature' ] [ 'attributes' ] else : feat_dict [ 'attributes' ] = self . _dict [ 'attributes' ] return self . _dict | returns the feature as a dictionary | 153 | 7 |
244,896 | def geometry ( self ) : if arcpyFound : if self . _geom is None : if 'feature' in self . _dict : self . _geom = arcpy . AsShape ( self . _dict [ 'feature' ] [ 'geometry' ] , esri_json = True ) elif 'geometry' in self . _dict : self . _geom = arcpy . AsShape ( self . _dict [ 'geometry' ] , esri_json = True ) return self . _geom return None | returns the feature geometry | 115 | 5 |
244,897 | def fields ( self ) : if 'feature' in self . _dict : self . _attributes = self . _dict [ 'feature' ] [ 'attributes' ] else : self . _attributes = self . _dict [ 'attributes' ] return self . _attributes . keys ( ) | returns a list of feature fields | 65 | 7 |
244,898 | def geometryType ( self ) : if self . _geomType is None : if self . geometry is not None : self . _geomType = self . geometry . type else : self . _geomType = "Table" return self . _geomType | returns the feature s geometry type | 56 | 7 |
244,899 | def value ( self ) : if self . mosaicMethod == "esriMosaicNone" or self . mosaicMethod == "esriMosaicCenter" or self . mosaicMethod == "esriMosaicNorthwest" or self . mosaicMethod == "esriMosaicNadir" : return { "mosaicMethod" : "esriMosaicNone" , "where" : self . _where , "ascending" : self . _ascending , "fids" : self . fids , "mosaicOperation" : self . _mosaicOperation } elif self . mosaicMethod == "esriMosaicViewpoint" : return { "mosaicMethod" : "esriMosaicViewpoint" , "viewpoint" : self . _viewpoint . asDictionary , "where" : self . _where , "ascending" : self . _ascending , "fids" : self . _fids , "mosaicOperation" : self . _mosaicOperation } elif self . mosaicMethod == "esriMosaicAttribute" : return { "mosaicMethod" : "esriMosaicAttribute" , "sortField" : self . _sortField , "sortValue" : self . _sortValue , "ascending" : self . _ascending , "where" : self . _where , "fids" : self . _fids , "mosaicOperation" : self . _mosaicOperation } elif self . mosaicMethod == "esriMosaicLockRaster" : return { "mosaicMethod" : "esriMosaicLockRaster" , "lockRasterIds" : self . _localRasterIds , "where" : self . _where , "ascending" : self . _ascending , "fids" : self . _fids , "mosaicOperation" : self . _mosaicOperation } elif self . mosaicMethod == "esriMosaicSeamline" : return { "mosaicMethod" : "esriMosaicSeamline" , "where" : self . _where , "fids" : self . _fids , "mosaicOperation" : self . _mosaicOperation } else : raise AttributeError ( "Invalid Mosaic Method" ) | gets the mosaic rule object as a dictionary | 516 | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.