Exemplo n.º 1
0
    def getObjectIDsInAOI(self, areaOfInterestVerticesDictionary):
        """Returns the ObjectIDs for each item in the AGOL Feature Service that
        that fall within an end user provided area of interst.
        it is best to use this method as ObjectIDs may not be sequential.
        for example the ObjectIDs could number 1,2,3,5,6,12,13... this
        is a result of delete field collected data after syncing
        """

        errorText = '''when trying to find points
        that fall within the provided area of interest'''
        errorMessage = errorMessageGenerator(errorText)

        urlEncodedParameters = urllib.urlencode({
            "geometryType":
            "esriGeometryPolygon",
            "spatialRel":
            "esriSpatialRelContains",
            "inSR":
            4326,
            "geometry":
            areaOfInterestVerticesDictionary
        })
        queryAGOLURL = 'query?where=1=1&returnIdsOnly=true&f=json&token='
        urlRequestString = '{}/{}/{}{}'.format(self.url, self.layerNumber,
                                               queryAGOLURL, self.token)

        featureServiceObjectIDs = urlRequest(urlRequestString,
                                             urlEncodedParameters)

        featureServiceObjectIDs = jsonObjectErrorHandling(
            featureServiceObjectIDs, "objectIds", errorMessage)

        featureServiceObjectIDs = featureServiceObjectIDs[:]
        featureServiceObjectIDs = listStringJoiner(featureServiceObjectIDs)
        return featureServiceObjectIDs
Exemplo n.º 2
0
    def queryObjectIDsForAttachments(self, AGOLfeatureServiceOjbectIDs):
        """Returns the ObjectIds for each feature in the AGOL Feature Service
        which has attachments.
        """

        errorText = '''when trying to retrieve objectIDs for
        input feature service'''
        errorMessage = errorMessageGenerator(errorText)

        urlEncodedParameters = urllib.urlencode(
            {"objectIds": AGOLfeatureServiceOjbectIDs})
        urlRequestString = "{}/{}/queryAttachments?&f=json&token={}".format(
            self.url, self.layerNumber, self.token)

        featureServiceObjectIDsThatHaveAttachmentsURL = urlRequest(
            urlRequestString, urlEncodedParameters)

        featureServiceObjectIDswithAttacments = jsonObjectErrorHandling(
            featureServiceObjectIDsThatHaveAttachmentsURL, "attachmentGroups",
            errorMessage)

        featureServiceObjectIDswithAttacments = [
            objectIDWithPhoto["parentObjectId"]
            for objectIDWithPhoto in featureServiceObjectIDswithAttacments
        ]

        featureServiceObjectIDswithAttacments = listStringJoiner(
            featureServiceObjectIDswithAttacments)

        return featureServiceObjectIDswithAttacments
Exemplo n.º 3
0
    def layerHasPhotoAttachments(self):
        """Checks to see if an AGOL Feature Service has attachments."""

        errorText = '''when trying to see if the input feature service
            has attachments or the input feature service does
            not allow attachments.'''

        errorMessage = errorMessageGenerator(errorText)
        areThereAttachmentsURL = urlRequest("{}/{}?&f=json&token={}".format(
            self.url, self.layerNumber, self.token))
        if jsonObjectErrorHandling(areThereAttachmentsURL, "hasAttachments",
                                   errorMessage):
            return True
Exemplo n.º 4
0
    def name(self):
        """Returns the name of the AGOL Feature
         Service from the input AGOL Feature Service URL
        """

        errorText = '''There was an error trying to retreive
        the name of the input feature service'''
        errorMessage = errorMessageGenerator(errorText)

        AGOLFeatureServiceNameURL = urlRequest("{0}?&f=json&token={1}".format(
            self.url, self.token))
        AGOLFeatureServiceName = jsonObjectErrorHandling(
            AGOLFeatureServiceNameURL, "layers", errorMessage)
        AGOLFeatureServiceName = AGOLFeatureServiceName[0]
        AGOLFeatureServiceName = AGOLFeatureServiceName["name"].encode(
            'utf-8', 'ignore')
        return AGOLFeatureServiceName
Exemplo n.º 5
0
    def getObjectIDs(self):
        """Returns the ObjectIDs for each item in the AGOL Feature Service.
        it is best to use this method as ObjectIDs may not be sequential.
        for example the ObjectIDs could number 1,2,3,5,6,12,13... this
        is a result of delete field collected data after syncing
        """

        errorText = '''when trying to retrieve the ObjectIds
        for the input feature service'''
        errorMessage = errorMessageGenerator(errorText)

        featureServiceObjectIDsURL = urlRequest(
            "{0}/{1}/query?where=1=1&returnIdsOnly=true&f=json&token={2}".
            format(self.url, self.layerNumber, self.token))
        featureServiceObjectIDs = jsonObjectErrorHandling(
            featureServiceObjectIDsURL, "objectIds", errorMessage)
        featureServiceObjectIDs = featureServiceObjectIDs[:]
        featureServiceObjectIDs = listStringJoiner(featureServiceObjectIDs)
        return featureServiceObjectIDs
Exemplo n.º 6
0
def getStatusURLForAGOLReplica(
        AGOLFeatureServiceName, AGOLFeatureServiceURL, AGOLToken,
        AGOLFeatureServiceLayerNumber, AGOLFeatureServiceObjectIDs):

    errorText = '''trying to retrieve the status URL for the replica
    of the AGOL Feature Service'''
    errorMessage = errorMessageGenerator(errorText)
    replicaParameters = urllib.urlencode(
        {
            "name": AGOLFeatureServiceName,
            "layers": AGOLFeatureServiceLayerNumber,
            "layerQueries": {
                AGOLFeatureServiceLayerNumber:
                {
                    "where": "OBJECTID IN ({})".format(
                        AGOLFeatureServiceObjectIDs)
                }
            },
            "transportType": "esriTransportTypeUrl",
            "returnAttachments": True,
            "returnAttachmentsDatabyURL": True,
            "syncDirection": "bidirectional",
            "attachmentsSyncDirection": "bidirectional",
            "async": True,
            "syncModel": "none",
            "dataFormat": "filegdb",
        }
    )

    createFeatureServieReplicaURL = "{}/createReplica/?f=json&token={}".format(
        AGOLFeatureServiceURL, AGOLToken)
    featureServiceCreateRepilcaRequest = urlRequest(
        createFeatureServieReplicaURL, replicaParameters)

    featureServiceReplicaStatusUrl = jsonObjectErrorHandling(
        featureServiceCreateRepilcaRequest, "statusUrl", errorMessage)

    return featureServiceReplicaStatusUrl