Exemplo n.º 1
0
def handle_ObjectRemovedEvent(site, uid):
    token = get_auth_token()

    fid = _get_obj_OBJECTID(obj=None, uid=uid, token=token)

    logger.info("ArcGIS: Deleting CaseStudy with OBJECTID %s", fid)

    res = apply_edits(fid, op='deletes', token=token)

    assert res['deleteResults']
    assert res['deleteResults'][0]['objectId'] == fid
Exemplo n.º 2
0
def handle_ObjectStateModified(site, uid):
    """ Handle when a CaseStudy is published / unpublished

    If published:
        * if this is a working copy, abort
        * check if object already exists in ArcGIS
            * if doesn't exist, add one
            * if exists, update the existing one
    If unpublished:
        * if this is a working copy, abort
        * check if object exists in ArcGIS
            * if exists, remove it
    """
    obj = _get_obj_by_measure_id(site, uid)
    if IWorkingCopy.providedBy(obj):
        logger.debug("Skipping CaseStudy status change processing")
        return

    state = get_state(obj)

    token = get_auth_token()
    fid = _get_obj_FID(obj=obj, token=token)

    if (state != 'published') and fid:
        # it's unpublished, we'll remove the object
        logger.info("ArcGIS: Deleting CaseStudy with FID %s", fid)

        res = apply_edits(fid, op='deletes', token=token)

        assert res['deleteResults']
        assert res['deleteResults'][0]['objectId'] == fid
        return

    if state == "published":
        repr = obj._repr_for_arcgis()

        # new case study, add it to ArcGIS
        if fid is None:
            logger.info("ArcGIS: Adding CaseStudy with measure id %s", uid)
            entry = json.dumps([repr])
            res = apply_edits(entry, op='adds', token=token)
            assert len(res.get('addResults', [])) == 1
            assert res['addResults'][0]['success'] == True

        # existing case study, sync its info
        else:
            logger.info("ArcGIS: Updating CaseStudy with FID %s", fid)

            repr['attributes']['FID'] = fid
            entry = json.dumps([repr])
            res = apply_edits(entry, op='updates', token=token)

            assert res['updateResults']
            assert res['updateResults'][0]['objectId'] == fid
Exemplo n.º 3
0
def handle_ObjectRemovedEvent(site, uid):
    token = get_auth_token()

    fid = _get_obj_FID(obj=None, uid=uid, token=token)

    logger.info("ArcGIS: Deleting CaseStudy with FID %s", fid)

    res = apply_edits(fid, op='deletes', token=token)

    assert res['deleteResults']
    assert res['deleteResults'][0]['objectId'] == fid
Exemplo n.º 4
0
def handle_ObjectModifiedEvent(site, uid):
    obj = _get_obj_by_measure_id(site, uid)
    repr = obj._repr_for_arcgis()

    token = get_auth_token()

    fid = _get_obj_OBJECTID(obj, token=token)

    if fid is None:
        logger.info("ArcGIS: Adding CaseStudy with measure id %s", uid)
        entry = json.dumps([repr])
        res = apply_edits(entry, op='adds', token=token)
        assert len(res.get('addResults', [])) == 1
        assert res['addResults'][0]['success'] is True
    else:
        repr['attributes']['OBJECTID'] = fid

        logger.info("ArcGIS: Updating CaseStudy with OBJECTID %s", fid)

        entry = json.dumps([repr])
        res = apply_edits(entry, op='updates', token=token)

        assert res['updateResults']
        assert res['updateResults'][0]['objectId'] == fid
Exemplo n.º 5
0
def handle_ObjectModifiedEvent(site, uid):
    obj = _get_obj_by_measure_id(site, uid)
    repr = obj._repr_for_arcgis()

    token = get_auth_token()

    fid = _get_obj_FID(obj, token=token)

    if fid is None:
        logger.info("ArcGIS: Adding CaseStudy with measure id %s", uid)
        entry = json.dumps([repr])
        res = apply_edits(entry, op='adds', token=token)
        assert len(res.get('addResults', [])) == 1
        assert res['addResults'][0]['success'] == True
    else:
        repr['attributes']['FID'] = fid

        logger.info("ArcGIS: Updating CaseStudy with FID %s", fid)

        entry = json.dumps([repr])
        res = apply_edits(entry, op='updates', token=token)

        assert res['updateResults']
        assert res['updateResults'][0]['objectId'] == fid
def main():
    # Needs env vars:
    #     LD_LIBRARY_PATH=<buildout-directory>/parts/gdal-compile/lib
    #     GISPASS=''

    token = get_auth_token()

    if sys.argv[1] == 'url':

        url = get_feature_url()
        #url = _get_token_service_url(endpoint)
        token = get_auth_token()
        print
        print "Token:", token
        print
        print "Feature URL: ", url + "?token=" + token
        print
        print "Query URL: ", url + "/query?token=" + token
        print

    elif sys.argv[1] == 'dump':
        print "Dumping..."
        if len(sys.argv) > 2:
            path = sys.argv[2]
        else:
            path = 'out.xml'
        res = query_layer(token=token)
        backup_data(res['features'], path=path)

    elif sys.argv[1] == 'summary':
        res = query_layer(token=token)
        print "Summary {0} entries...".format(len(res['features']))
        for entry in res['features']:
            geo = '{0} x {1}'.format(*entry['geometry'].values())
            attr = entry['attributes']
            print attr['FID'], ': ', attr['itemname'], ' @ ', geo

    elif sys.argv[1] == 'del':
        print "Deleting..."
        fid = sys.argv[2]
        res = delete_casestudy(int(fid))
        print res

    elif sys.argv[1] == 'delall':
        print "Deleting all..."
        print delete_all_casestudies(token)

    elif sys.argv[1] == 'addall':
        path = sys.argv[2]
        print add_all_casestudies(path, token)

    elif sys.argv[1] == 'edit':
        print "Editing..."
        fid = sys.argv[2]
        path = sys.argv[3]
        edit_casestudy(fid, path, token)

    elif sys.argv[1] == 'getfid':
        print "Getting FID for measureid..."
        measureid = sys.argv[2]
        print "FID: ", _get_obj_FID(uid=int(measureid))

    else:
        print "Invalid command"
def main():
    # Needs env vars:
    #     LD_LIBRARY_PATH=<buildout-directory>/parts/gdal-compile/lib
    #     GISPASS=''

    parser = argparse.ArgumentParser(
        description="Manual operations with ArcGIS"
    )
    parser.add_argument("-u", "--get-feature-url", action="store_true")
    parser.add_argument("-d", "--dump", action="store_true")
    parser.add_argument("-s", "--summary", action="store_true")

    parser.add_argument("-x", "--delete", action="store_true")
    parser.add_argument("-g", "--get-fid", action="store_true")

    parser.add_argument("fid", nargs="?", type=int, default=None)

    parser.add_argument("-X", "--delete-all", action="store_true")

    parser.add_argument("-f", "--import-file", type=str, action="store")
    parser.add_argument("-e", "--edit-file", type=str, action="store")

    args = parser.parse_args()

    passwd = os.environ.get('GISPASS')

    if not passwd:
        logger.error("You need to provide the GISPASS env variable")
        sys.exit(1)

    token = get_auth_token()

    if args.get_feature_url:
        url = get_feature_url()
        # url = _get_token_service_url(endpoint)
        logger.warning(" ")
        logger.warning("Token: %s", token)
        logger.warning(" ")
        logger.warning("Feature URL: %s ?token= %s", url, token)
        logger.warning(" ")
        logger.warning("Query URL: %s/query?token=%s", url,  token)
        logger.warning(" ")
        
    if args.dump:
        logger.warning("Dumping...")

        if len(sys.argv) > 2:
            path = sys.argv[2]
        else:
            path = 'out.xml'
        res = query_layer(token=token)
        backup_data(res['features'], path=path)

    if args.summary:
        res = query_layer(token=token)
        logger.warning("Summary %s entries.... ", len(res['features']))

        for entry in res['features']:
            geo = '{0} x {1}'.format(*entry['geometry'].values())
            attr = entry['attributes']
            logger.warning('%s:%s @ %s', attr['OBJECTID'], attr['itemname'], geo)

    if args.delete:
        logger.warning("Deleting...")
        res = delete_casestudy(args.fid, token)
        logger.warning(res)

    if args.delete_all:
        logger.warning("Deleting all...")
        logger.warning(delete_all_casestudies(token))

    if args.import_file:
        logger.warning(add_all_casestudies(args.import_file, token))

    if args.edit_file:
        logger.warning("Editing...")
        fid = args.fid
        assert fid is not None
        edit_casestudy(fid, args.edit_file, token)

    if args.get_fid:
        logger.warning ("Getting OBJECTID for measureid...")
        measureid = args.fid    # I know, fake
        logger.warning("OBJECTID: %s", _get_obj_OBJECTID(uid=int(measureid)))

    logger.warning("No arguments")
Exemplo n.º 8
0
def handle_ObjectStateModified(site, uid):
    """ Handle when a CaseStudy is published / unpublished

    If published:
        * if this is a working copy, abort
        * check if object already exists in ArcGIS
            * if doesn't exist, add one
            * if exists, update the existing one
    If unpublished:
        * if this is a working copy, abort
        * check if object exists in ArcGIS
            * if exists, remove it
    """
    obj = _get_obj_by_measure_id(site, uid)

    if IWorkingCopy.providedBy(obj):
        logger.debug("Skipping CaseStudy status change processing")

        return

    state = get_state(obj)

    try:
        token = get_auth_token()
    except KeyError:
        logger.exception("Could not get an Arcgis auth token")

        return

    fid = _get_obj_OBJECTID(obj=obj, token=token)

    if (state != 'published') and fid:
        # it's unpublished, we'll remove the object
        logger.info("ArcGIS: Deleting CaseStudy with OBJECTID %s", fid)

        res = apply_edits(fid, op='deletes', token=token)

        assert res['deleteResults']
        assert res['deleteResults'][0]['objectId'] == fid

        return

    if state == "published":
        repr = obj._repr_for_arcgis()

        # new case study, add it to ArcGIS

        if fid is None:
            logger.info("ArcGIS: Adding CaseStudy with measure id %s", uid)
            entry = json.dumps([repr])
            res = apply_edits(entry, op='adds', token=token)
            assert len(res.get('addResults', [])) == 1
            assert res['addResults'][0]['success'] is True

        # existing case study, sync its info
        else:
            logger.info("ArcGIS: Updating CaseStudy with OBJECTID %s", fid)

            repr['attributes']['OBJECTID'] = fid
            entry = json.dumps([repr])
            res = apply_edits(entry, op='updates', token=token)

            assert res['updateResults']
            assert res['updateResults'][0]['objectId'] == fid