def main(argv=sys.argv): if len(argv) != 2: usage(argv) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) translation_manager.options.update({ 'locales': settings['available_languages'].split(), 'get_locale_fallback': True }) configure_mappers() postgis_version = DBSession.execute(func.postgis_version()).scalar() if not postgis_version.startswith('2.'): # With PostGIS 1.x the AddGeometryColumn and DropGeometryColumn # management functions should be used. Area.__table__.c.geometry.type.management = True Task.__table__.c.geometry.type.management = True Base.metadata.drop_all(engine) Base.metadata.create_all(engine) with transaction.manager: geometry = '{"type":"MultiPolygon","coordinates":[[[[0.9439973,48.1124991],[0.9439617,48.1124316],[0.9436539,48.1123846],[0.9435646,48.1123915],[0.9435327,48.1124159],[0.9435101,48.1124985],[0.9434772,48.1125175],[0.9426452,48.1123642],[0.9425722,48.112333],[0.9422699,48.1120818],[0.9421995,48.1120605],[0.9421477,48.1120648],[0.9420632,48.112103],[0.941881,48.1122479],[0.9418038,48.1122679],[0.9417503,48.1122513],[0.9415619,48.1121153],[0.9414559,48.1120661],[0.9413928,48.1120672],[0.9409135,48.1121726],[0.9408424,48.1121538],[0.9407001,48.112081],[0.9406476,48.1120888],[0.940564,48.1121817],[0.9404357,48.1122414],[0.9403099,48.112273],[0.9399965,48.1122711],[0.9396713,48.1123254],[0.9393974,48.1122674],[0.9392938,48.1122742],[0.939251,48.1123041],[0.9391999,48.1123871],[0.9391291,48.1124258],[0.9390605,48.1124212],[0.9387723,48.1123216],[0.9387038,48.112312],[0.9385911,48.112324],[0.938539,48.1123602],[0.9384626,48.1124552],[0.938409,48.1124857],[0.9382915,48.1124816],[0.937814,48.1123474],[0.9373468,48.1121692],[0.9372416,48.1121531],[0.9370728,48.11222],[0.9368963,48.1122388],[0.9368195,48.1122207],[0.9366888,48.1120758],[0.9366305,48.1120462],[0.9365513,48.1120533],[0.9364563,48.1121898],[0.9364051,48.112215],[0.9362435,48.1122447],[0.9360775,48.1122529],[0.935965,48.1122311],[0.9358367,48.1121436],[0.9356261,48.1121597],[0.9354644,48.1121544],[0.935367,48.1121832],[0.9353183,48.1122211],[0.9353043,48.1123266],[0.9352257,48.1123409],[0.9351053,48.1123109],[0.9349266,48.112308],[0.9349437,48.1122208],[0.935028,48.1121111],[0.9350097,48.1120778],[0.9349264,48.1120525],[0.9348114,48.1120507],[0.9345203,48.1121667],[0.934303,48.1121371],[0.9341118,48.1120827],[0.9336163,48.1118631],[0.9334011,48.1118632],[0.9333406,48.1118784],[0.9333018,48.1119087],[0.9332712,48.1120369],[0.9332095,48.1120514],[0.9326641,48.1119703],[0.9324749,48.1119783],[0.9323901,48.1120035],[0.9320996,48.1121894],[0.932001,48.1122266],[0.9318959,48.1122429],[0.9318205,48.1122366],[0.9317522,48.1121982],[0.9315106,48.111858],[0.9314835,48.111855],[0.9313209,48.111955],[0.9311756,48.1119605],[0.9310817,48.111943],[0.9308539,48.111838],[0.93077,48.1118461],[0.9306913,48.1120577],[0.9306603,48.1120802],[0.9304127,48.1120509],[0.9301916,48.1121665],[0.9301366,48.1121803],[0.9300427,48.1121754],[0.9299711,48.112132],[0.9296377,48.1117226],[0.929518,48.1116539],[0.9291236,48.1115423],[0.928688,48.1113557],[0.9284554,48.1112127],[0.928209,48.1111933],[0.9276319,48.1110024],[0.9272926,48.1109949],[0.92716,48.1109442],[0.9268904,48.1107475],[0.9267995,48.1106985],[0.926513,48.1105908],[0.9257587,48.110361],[0.9256844,48.1103175],[0.9252016,48.1099046],[0.9247036,48.1095281],[0.9238873,48.1089805],[0.9234698,48.1087463],[0.9230175,48.1085317],[0.9228205,48.1084023],[0.9226396,48.1082393],[0.9223989,48.1079389],[0.9221707,48.1076004],[0.9220664,48.1074937],[0.9218263,48.1073359],[0.9206929,48.1067142],[0.9202506,48.1064974],[0.9194249,48.1061589],[0.9189929,48.1059179],[0.9185714,48.1056273],[0.918382,48.1054632],[0.9181514,48.1051805],[0.9180088,48.105076],[0.9178621,48.1050116],[0.9177965,48.1049636],[0.917625,48.1047545],[0.9174401,48.1046548],[0.9171922,48.1045622],[0.9171528,48.1045598],[0.9170589,48.1046051],[0.916151,48.1044458],[0.9157368,48.1043942],[0.9155837,48.104331],[0.9153533,48.1043506],[0.9152267,48.1043078],[0.9151469,48.1043302],[0.9144978,48.1042957],[0.9138818,48.1042867],[0.913612,48.1042512],[0.9135344,48.1042158],[0.91342,48.1041083],[0.9133722,48.1040059],[0.9133453,48.1038797],[0.9124999,48.1037314],[0.9120556,48.103698],[0.9119134,48.1036545],[0.9114243,48.1035828],[0.9110642,48.1034704],[0.9107811,48.1034509],[0.9106821,48.103419],[0.9104466,48.103264],[0.9103186,48.1031233],[0.9102487,48.1031311],[0.9101926,48.103167],[0.9101209,48.1032555],[0.9099347,48.1033954],[0.9097093,48.1035337],[0.9093202,48.1037211],[0.9091969,48.1037633],[0.9088825,48.1038087],[0.908232,48.1038471],[0.9079792,48.1039572],[0.9078613,48.1039921],[0.9073389,48.1040699],[0.9069709,48.1040314],[0.9067374,48.1040984],[0.9062589,48.1041359],[0.9059745,48.1041992],[0.9056679,48.1041682],[0.9050763,48.1042027],[0.904938,48.1041824],[0.9048179,48.1041305],[0.9045452,48.1039603],[0.9044561,48.103924],[0.904196,48.1038809],[0.9036573,48.103662],[0.9034452,48.1035998],[0.903079,48.1035192],[0.9028311,48.103446],[0.9018642,48.1033358],[0.9013742,48.1032336],[0.9005004,48.1031099],[0.9002539,48.1030173],[0.9000271,48.1029553],[0.8980542,48.1026568],[0.8970976,48.1025458],[0.896599,48.1024688],[0.895392,48.1023392],[0.8944552,48.1023009],[0.8943655,48.1022504],[0.893184,48.1021089],[0.892454,48.1020611],[0.8907345,48.102055],[0.8890399,48.1021236],[0.8871747,48.100757],[0.8867015,48.1002951],[0.8856048,48.099084],[0.8853025,48.0987087],[0.8852286,48.0986621],[0.8849884,48.0986016],[0.8850231,48.0983716],[0.8849404,48.0983012],[0.88507,48.0980405],[0.8852975,48.0976653],[0.8852704,48.0976029],[0.8851619,48.0975104],[0.8850349,48.0958233],[0.884925,48.09557],[0.8845941,48.0949965],[0.8844349,48.094641],[0.8839767,48.094183],[0.883877,48.0940455],[0.8838347,48.0939336],[0.8838474,48.0937614],[0.8838277,48.0937378],[0.8836345,48.0937005],[0.8835989,48.0936473],[0.8835399,48.0932616],[0.8835453,48.0931402],[0.8836322,48.0929363],[0.8837115,48.0928221],[0.8839719,48.0925712],[0.8840114,48.0924936],[0.8841869,48.0918922],[0.884514,48.0909761],[0.8845052,48.0909363],[0.8841545,48.0909667],[0.8840605,48.0909899],[0.8840665,48.0909786],[0.88377,48.0910244],[0.8821938,48.0913622],[0.8822637,48.090884],[0.8822353,48.0904922],[0.8816999,48.0878551],[0.8816151,48.0876328],[0.8814922,48.0874268],[0.8814738,48.0874217],[0.8814855,48.0874104],[0.8814306,48.0872591],[0.8815099,48.0869485],[0.8815416,48.086688],[0.8813337,48.0861234],[0.8813029,48.086034],[0.8813103,48.0858493],[0.881293,48.0858045],[0.881064,48.0855132],[0.8809225,48.0852696],[0.8809149,48.0851904],[0.880876,48.0851082],[0.8807837,48.0850312],[0.8805608,48.0849696],[0.87945,48.0845884],[0.8794268,48.0845672],[0.879631,48.0841288],[0.8799079,48.083644],[0.880107,48.0831259],[0.880317,48.0828603],[0.8804452,48.0827907],[0.8808702,48.0826873],[0.8809531,48.0826021],[0.8810799,48.0825662],[0.881479,48.0823449],[0.8818056,48.0820532],[0.8818558,48.081984],[0.8819116,48.0817215],[0.8818362,48.0817037],[0.8819608,48.0813496],[0.8819926,48.0813395],[0.8823055,48.0813597],[0.8823133,48.0812496],[0.8824595,48.0807075],[0.8824582,48.0806392],[0.8823237,48.080407],[0.8821394,48.08017],[0.881799,48.0798468],[0.8816261,48.0796064],[0.8816053,48.0795361],[0.8816229,48.0793828],[0.8815777,48.0788658],[0.8819271,48.0726864],[0.8819837,48.0726738],[0.8827333,48.0724684],[0.8834216,48.0723433],[0.8838909,48.0722909],[0.8861918,48.0721536],[0.8870951,48.07213],[0.8885457,48.0721751],[0.8890476,48.0722146],[0.8897387,48.0722913],[0.8924092,48.0726618],[0.8929554,48.0726915],[0.8938723,48.0726924],[0.8952958,48.0725969],[0.895799,48.0725847],[0.8971856,48.0726643],[0.898136,48.0727578],[0.8990872,48.0728791],[0.899557,48.0729567],[0.9001325,48.0730757],[0.9029573,48.0737891],[0.9038139,48.0740308],[0.9070093,48.0750725],[0.9081086,48.0753728],[0.9099514,48.0758167],[0.910322,48.0759223],[0.9117924,48.0765358],[0.9126649,48.0768328],[0.9132159,48.0769866],[0.9137789,48.0771191],[0.9143513,48.0772292],[0.9149079,48.0773127],[0.9168405,48.0772668],[0.9194871,48.0771411],[0.9199632,48.0770987],[0.9207016,48.0771334],[0.9227369,48.0770818],[0.9227977,48.0771217],[0.9237378,48.0774408],[0.9242799,48.077677],[0.9245315,48.0777642],[0.9259242,48.078126],[0.9259835,48.0781653],[0.9257486,48.0782691],[0.9250651,48.0786527],[0.9250171,48.0787207],[0.9250181,48.078768],[0.9250785,48.0788498],[0.9251769,48.0789144],[0.9253266,48.078969],[0.9253932,48.0790145],[0.9254937,48.0791402],[0.925567,48.0791978],[0.9257456,48.0791989],[0.9258597,48.0791272],[0.9259201,48.0790553],[0.9259676,48.0788869],[0.9260389,48.07885],[0.9262833,48.078847],[0.9263631,48.0788613],[0.9272144,48.0791422],[0.928243,48.0794004],[0.9287124,48.0795397],[0.9288762,48.0796129],[0.9291839,48.07988],[0.9292587,48.080876],[0.9290689,48.081457],[0.9286252,48.0830512],[0.9286038,48.0830777],[0.92844,48.0830836],[0.9281558,48.0834763],[0.9277933,48.083806],[0.9278103,48.0838341],[0.927992,48.0839684],[0.9281209,48.0840093],[0.9281962,48.0840779],[0.9286212,48.0846534],[0.9288801,48.0845032],[0.9290658,48.0843593],[0.9291169,48.0843561],[0.9291326,48.0843802],[0.9290639,48.0845228],[0.9290714,48.084559],[0.9291115,48.084589],[0.9293888,48.0846715],[0.9297144,48.0849806],[0.9299357,48.0850234],[0.9300327,48.0850594],[0.9300734,48.0851101],[0.9301458,48.0853341],[0.9300687,48.0855351],[0.9301256,48.085745],[0.9300608,48.0859372],[0.9301152,48.0860054],[0.9301412,48.0861604],[0.9301083,48.0863554],[0.9301356,48.0864634],[0.9305376,48.0870193],[0.9306298,48.0870276],[0.9311066,48.0868727],[0.9311625,48.0868716],[0.9313259,48.0869521],[0.9318028,48.0880182],[0.9318266,48.0881523],[0.9319901,48.0884926],[0.9320287,48.0885328],[0.9327689,48.0884882],[0.933996,48.0883107],[0.93406,48.0888072],[0.9358186,48.0885738],[0.9379588,48.088448],[0.9404128,48.0884739],[0.9404298,48.0884615],[0.9404271,48.087987],[0.9409544,48.0880107],[0.9436225,48.0909035],[0.944013,48.0912746],[0.9445871,48.0917695],[0.9446888,48.0918275],[0.9448178,48.0918585],[0.9450145,48.0919347],[0.9452888,48.0920105],[0.9456031,48.0921922],[0.9458274,48.0925722],[0.9461027,48.0929715],[0.9467571,48.0937549],[0.9466013,48.0939368],[0.9457586,48.0946713],[0.9449309,48.0951669],[0.9442778,48.0957071],[0.9431922,48.0967234],[0.9430035,48.0968566],[0.9427329,48.0970077],[0.9428798,48.0970882],[0.9436925,48.0974573],[0.9442749,48.097623],[0.9449722,48.0979461],[0.9449351,48.0979618],[0.9446782,48.0981461],[0.9446701,48.0981728],[0.9447244,48.098264],[0.9447744,48.098652],[0.9448442,48.0989081],[0.9448821,48.0989785],[0.9450293,48.099123],[0.9452603,48.0993019],[0.9454104,48.0994448],[0.9454708,48.0996084],[0.9455327,48.099971],[0.9457118,48.1002634],[0.9457302,48.1003421],[0.9457144,48.1005718],[0.945601,48.1009101],[0.9455879,48.1010401],[0.9454882,48.1012024],[0.9454903,48.1017689],[0.9457282,48.1019203],[0.9459384,48.10198],[0.9459877,48.1020078],[0.9461158,48.1021672],[0.9461662,48.1022786],[0.9461757,48.102371],[0.9464741,48.1027264],[0.9465394,48.1029182],[0.9467153,48.103137],[0.9467236,48.1032315],[0.9466626,48.1033925],[0.9466604,48.1034558],[0.9468874,48.1037169],[0.9469397,48.1038022],[0.9469778,48.1041225],[0.9469578,48.104168],[0.9469827,48.1042705],[0.9469437,48.1044249],[0.9469577,48.1045391],[0.9469388,48.1046384],[0.9469778,48.1047147],[0.9470086,48.1047847],[0.9473819,48.1050776],[0.9474707,48.1051754],[0.9475253,48.1052809],[0.9475305,48.1054269],[0.9475663,48.1055737],[0.9475898,48.1056804],[0.9475196,48.1057741],[0.9473788,48.1058605],[0.9472747,48.106018],[0.9471141,48.1062086],[0.9471387,48.1063949],[0.94701,48.1067945],[0.9470153,48.1069376],[0.9469803,48.1069933],[0.946806,48.1070801],[0.9466969,48.1071462],[0.9466209,48.1072286],[0.9464116,48.1072491],[0.9462462,48.1072746],[0.9460057,48.107246],[0.9457974,48.1073321],[0.9456807,48.1074036],[0.9453011,48.1076196],[0.9449878,48.1078416],[0.9448832,48.1079474],[0.9448628,48.1082604],[0.944825,48.1086698],[0.9448109,48.1089699],[0.9447343,48.1098883],[0.9447134,48.1101126],[0.9445625,48.1101423],[0.9444986,48.1102203],[0.9444422,48.1103438],[0.9445083,48.1106833],[0.9446679,48.1108109],[0.9446864,48.1108429],[0.9445882,48.1109482],[0.9445629,48.1110658],[0.9445243,48.1111079],[0.9444333,48.1111562],[0.9443598,48.1111432],[0.9442693,48.1112372],[0.9442649,48.1113383],[0.9442985,48.1114212],[0.9444328,48.1115197],[0.9444457,48.1115469],[0.9444051,48.1116867],[0.9444106,48.1118206],[0.9442092,48.1119209],[0.9441154,48.1120517],[0.9439546,48.112119],[0.9438787,48.1122846],[0.9438909,48.1123155],[0.9440504,48.1123422],[0.9440828,48.11236],[0.9439973,48.1124991]]]]}' # noqa geometry = geojson.loads(geometry, object_hook=geojson.GeoJSON.to_instance) geometry = shapely.geometry.asShape(geometry) geometry = shape.from_shape(geometry, 4326) area = Area( geometry ) DBSession.add(area) project = Project( 'Map all primary roads' ) project.area = area project.short_description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." # noqa project.description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." # noqa DBSession.add(project) with project.force_locale('fr'): project.name = "Cartographier les routes" project.auto_fill(14) license = License() license.name = 'NextView' license.description = "This data is licensed for use by the US Government (USG) under the NextView (NV) license and copyrighted by Digital Globe or GeoEye. The NV license allows the USG to share the imagery and Literal Imagery Derived Products (LIDP) with entities outside the USG when that entity is working directly with the USG, for the USG, or in a manner that is directly beneficial to the USG. The party receiving the data can only use the imagery or LIDP for the original purpose or only as otherwise agreed to by the USG. The party receiving the data cannot share the imagery or LIDP with a third party without express permission from the USG. At no time should this imagery or LIDP be used for other than USG-related purposes and must not be used for commercial gain. The copyright information should be maintained at all times. Your acceptance of these license terms is implied by your use." # noqa license.plain_text = "In other words, you may only use NextView imagery linked from this site for digitizing OpenStreetMap data for humanitarian purposes." # noqa DBSession.add(license) license = License() license.name = 'Astrium/UNOSAT' license.description = "UNOSAT allow any INTERNET USER to use the IMAGE to develop DERIVATIVE WORKS provided that the INTERNET USER includes the DERIVATIVE WORKS he/she created in the OpenStreetMap database under CC-BY-SA licence (http://creativecommons.org/licenses/by-sa/2.0/) and/or Open Database licence (ODbL: http://www.opendatacommons.org/licenses/odbl/), with the credit of the corresponding PRODUCT conspicuously displayed and written in full, in order to allow any OpenStreetMap database user to have access to and to use the DERIVATIVE WORKS. Except for the foregoing, the END USER and/or the INTERNET USER shall not be entitled to sell, distribute, assign, dispose of, lease, sublicense or transfer, directly or indirectly, any DERIVATIVE WORKS to any third party." # noqa license.plain_text = "Astrium GEO-Information Services and UNOSAT are allowing access to this imagery for creating information in OpenStreetMap. Other uses are not allowed." # noqa DBSession.add(license)
def __init__(self, database, context, app_root=None, table='records', repo_filter=None): ''' Initialize repository ''' self.context = context self.filter = repo_filter self.fts = False # Don't use relative paths, this is hack to get around # most wsgi restriction... if (app_root and database.startswith('sqlite:///') and not database.startswith('sqlite:////')): database = database.replace('sqlite:///', 'sqlite:///%s%s' % (app_root, os.sep)) self.engine = Repository.create_engine('%s' % database) base = declarative_base(bind=self.engine) LOGGER.debug('binding ORM to existing database') self.postgis_geometry_column = None schema, table = util.sniff_table(table) self.dataset = type( 'dataset', (base, ), dict(__tablename__=table, __table_args__={ 'autoload': True, 'schema': schema })) self.dbtype = self.engine.name self.session = create_session(self.engine) temp_dbtype = None if self.dbtype == 'postgresql': # check if PostgreSQL is enabled with PostGIS 1.x try: self.session.execute(select([func.postgis_version()])) temp_dbtype = 'postgresql+postgis+wkt' LOGGER.debug('PostgreSQL+PostGIS1+WKT detected') except Exception, err: LOGGER.debug('PostgreSQL+PostGIS1+WKT detection failed') # check if PostgreSQL is enabled with PostGIS 2.x try: self.session.execute('select(postgis_version())') temp_dbtype = 'postgresql+postgis+wkt' LOGGER.debug('PostgreSQL+PostGIS2+WKT detected') except Exception, err: LOGGER.debug('PostgreSQL+PostGIS2+WKT detection failed')
def __init__(self, database, context, app_root=None, table='records', repo_filter=None): ''' Initialize repository ''' self.context = context self.filter = repo_filter self.fts = False # Don't use relative paths, this is hack to get around # most wsgi restriction... if (app_root and database.startswith('sqlite:///') and not database.startswith('sqlite:////')): database = database.replace('sqlite:///', 'sqlite:///%s%s' % (app_root, os.sep)) self.engine = Repository.create_engine('%s' % database) base = declarative_base(bind=self.engine) LOGGER.debug('binding ORM to existing database') self.postgis_geometry_column = None schema, table = util.sniff_table(table) self.dataset = type('dataset', (base,), dict(__tablename__=table,__table_args__={'autoload': True, 'schema': schema})) self.dbtype = self.engine.name self.session = create_session(self.engine) temp_dbtype = None if self.dbtype == 'postgresql': # check if PostgreSQL is enabled with PostGIS 1.x try: self.session.execute(select([func.postgis_version()])) temp_dbtype = 'postgresql+postgis+wkt' LOGGER.debug('PostgreSQL+PostGIS1+WKT detected') except Exception, err: LOGGER.debug('PostgreSQL+PostGIS1+WKT detection failed') # check if PostgreSQL is enabled with PostGIS 2.x try: self.session.execute('select(postgis_version())') temp_dbtype = 'postgresql+postgis+wkt' LOGGER.debug('PostgreSQL+PostGIS2+WKT detected') except Exception, err: LOGGER.debug('PostgreSQL+PostGIS2+WKT detection failed')
def __init__(self, database, context, app_root=None, table='records', repo_filter=None): ''' Initialize repository ''' self.context = context self.filter = repo_filter self.fts = False # Don't use relative paths, this is hack to get around # most wsgi restriction... if (app_root and database.startswith('sqlite:///') and not database.startswith('sqlite:////')): database = database.replace('sqlite:///', 'sqlite:///%s%s' % (app_root, os.sep)) self.engine = Repository.create_engine('%s' % database) base = declarative_base(bind=self.engine) LOGGER.debug('binding ORM to existing database') self.postgis_geometry_column = None schema, table = util.sniff_table(table) self.dataset = type('dataset', (base,), dict(__tablename__=table,__table_args__={'autoload': True, 'schema': schema})) self.dbtype = self.engine.name self.session = create_session(self.engine) temp_dbtype = None if self.dbtype == 'postgresql': # check if PostgreSQL is enabled with PostGIS 1.x try: self.session.execute(select([func.postgis_version()])) temp_dbtype = 'postgresql+postgis+wkt' LOGGER.debug('PostgreSQL+PostGIS1+WKT detected') except Exception as err: LOGGER.debug('PostgreSQL+PostGIS1+WKT detection failed') # check if PostgreSQL is enabled with PostGIS 2.x try: self.session.execute('select(postgis_version())') temp_dbtype = 'postgresql+postgis+wkt' LOGGER.debug('PostgreSQL+PostGIS2+WKT detected') except Exception as err: LOGGER.debug('PostgreSQL+PostGIS2+WKT detection failed') # check if a native PostGIS geometry column exists try: result = self.session.execute("select f_geometry_column from geometry_columns where f_table_name = '%s' and f_geometry_column != 'wkt_geometry' limit 1;" % table) row = result.fetchone() self.postgis_geometry_column = str(row['f_geometry_column']) temp_dbtype = 'postgresql+postgis+native' LOGGER.debug('PostgreSQL+PostGIS+Native detected') except Exception as err: LOGGER.debug('PostgreSQL+PostGIS+Native not picked up: %s', str(err)) # check if a native PostgreSQL FTS GIN index exists result = self.session.execute("select relname from pg_class where relname='fts_gin_idx'").scalar() self.fts = bool(result) LOGGER.debug('PostgreSQL FTS enabled: %r', self.fts) if temp_dbtype is not None: LOGGER.debug('%s support detected' % temp_dbtype) self.dbtype = temp_dbtype if self.dbtype in ['sqlite', 'sqlite3']: # load SQLite query bindings # <= 0.6 behaviour if not __version__ >= '0.7': self.connection = self.engine.raw_connection() self.connection.create_function( 'query_spatial', 4, util.query_spatial) self.connection.create_function( 'update_xpath', 3, util.update_xpath) self.connection.create_function('get_anytext', 1, util.get_anytext) self.connection.create_function('get_geometry_area', 1, util.get_geometry_area) self.connection.create_function('get_spatial_overlay_rank', 2, util.get_spatial_overlay_rank) LOGGER.debug('setting repository queryables') # generate core queryables db and obj bindings self.queryables = {} for tname in self.context.model['typenames']: for qname in self.context.model['typenames'][tname]['queryables']: self.queryables[qname] = {} for qkey, qvalue in \ self.context.model['typenames'][tname]['queryables'][qname].iteritems(): self.queryables[qname][qkey] = qvalue # flatten all queryables # TODO smarter way of doing this self.queryables['_all'] = {} for qbl in self.queryables: self.queryables['_all'].update(self.queryables[qbl]) self.queryables['_all'].update(self.context.md_core_model['mappings'])
def __init__(self, database, context, app_root=None, table='records', repo_filter=None): ''' Initialize repository ''' self.context = context self.filter = repo_filter self.fts = False # Don't use relative paths, this is hack to get around # most wsgi restriction... if (app_root and database.startswith('sqlite:///') and not database.startswith('sqlite:////')): database = database.replace('sqlite:///', 'sqlite:///%s%s' % (app_root, os.sep)) self.engine = Repository.create_engine('%s' % database) base = declarative_base(bind=self.engine) LOGGER.info('binding ORM to existing database') self.postgis_geometry_column = None schema_name, table_name = table.rpartition(".")[::2] default_table_args = {"autoload": True, "schema": schema_name or None} column_constraints = context.md_core_model.get("column_constraints") # Note: according to the sqlalchemy docs available here: # # https://docs.sqlalchemy.org/en/14/orm/declarative_tables.html#declarative-table-configuration # # the __table_args__ attribute can either be a tuple or a dict if column_constraints is not None: table_args = tuple((*column_constraints, default_table_args)) else: table_args = default_table_args self.dataset = type('dataset', (base, ), { "__tablename__": table_name, "__table_args__": table_args, }) self.dbtype = self.engine.name self.session = create_session(self.engine) temp_dbtype = None if self.dbtype == 'postgresql': # check if PostgreSQL is enabled with PostGIS 1.x try: self.session.execute(select([func.postgis_version()])) temp_dbtype = 'postgresql+postgis+wkt' LOGGER.debug('PostgreSQL+PostGIS1+WKT detected') except Exception as err: LOGGER.exception('PostgreSQL+PostGIS1+WKT detection failed') # check if PostgreSQL is enabled with PostGIS 2.x try: self.session.execute('select(postgis_version())') temp_dbtype = 'postgresql+postgis+wkt' LOGGER.debug('PostgreSQL+PostGIS2+WKT detected') except Exception as err: LOGGER.exception('PostgreSQL+PostGIS2+WKT detection failed') # check if a native PostGIS geometry column exists try: result = self.session.execute( "select f_geometry_column " "from geometry_columns " "where f_table_name = '%s' " "and f_geometry_column != 'wkt_geometry' " "limit 1;" % table_name) row = result.fetchone() self.postgis_geometry_column = str(row['f_geometry_column']) temp_dbtype = 'postgresql+postgis+native' LOGGER.debug('PostgreSQL+PostGIS+Native detected') except Exception as err: LOGGER.exception('PostgreSQL+PostGIS+Native not picked up: %s', table_name) # check if a native PostgreSQL FTS GIN index exists result = self.session.execute( "select relname from pg_class where relname='fts_gin_idx'" ).scalar() self.fts = bool(result) LOGGER.debug('PostgreSQL FTS enabled: %r', self.fts) if temp_dbtype is not None: LOGGER.debug('%s support detected', temp_dbtype) self.dbtype = temp_dbtype if self.dbtype in ['sqlite', 'sqlite3']: # load SQLite query bindings # <= 0.6 behaviour if not __version__ >= '0.7': self.connection = self.engine.raw_connection() create_custom_sql_functions(self.connection) LOGGER.info('setting repository queryables') # generate core queryables db and obj bindings self.queryables = {} for tname in self.context.model['typenames']: for qname in self.context.model['typenames'][tname]['queryables']: self.queryables[qname] = {} for qkey, qvalue in \ self.context.model['typenames'][tname]['queryables'][qname].items(): self.queryables[qname][qkey] = qvalue # flatten all queryables # TODO smarter way of doing this self.queryables['_all'] = {} for qbl in self.queryables: self.queryables['_all'].update(self.queryables[qbl]) self.queryables['_all'].update(self.context.md_core_model['mappings'])
metadata = MetaData(engine) Base = declarative_base(metadata=metadata) class Lake(Base): __tablename__ = 'lake' id = Column(Integer, primary_key=True) geom = Column(Geometry(geometry_type='LINESTRING', srid=4326)) def __init__(self, geom): self.geom = geom session = sessionmaker(bind=engine)() postgis_version = session.execute(func.postgis_version()).scalar() if not postgis_version.startswith('2.'): # With PostGIS 1.x the AddGeometryColumn and DropGeometryColumn # management functions should be used. Lake.__table__.c.geom.type.management = True class IndexTest(unittest.TestCase): def setUp(self): metadata.drop_all(checkfirst=True) metadata.create_all() def tearDown(self): session.rollback() metadata.drop_all()
metadata = MetaData(engine) Base = declarative_base(metadata=metadata) class Lake(Base): __tablename__ = 'lake' id = Column(Integer, primary_key=True) geom = Column(Geometry(geometry_type='LINESTRING', srid=4326)) def __init__(self, geom): self.geom = geom session = sessionmaker(bind=engine)() postgis_version = session.execute(func.postgis_version()).scalar() if not postgis_version.startswith('2.'): # With PostGIS 1.x the AddGeometryColumn and DropGeometryColumn # management functions should be used. Lake.__table__.c.geom.type.management = True else: # The raster type is only available on PostGIS 2.0 and above class Ocean(Base): __tablename__ = 'ocean' id = Column(Integer, primary_key=True) rast = Column(Raster) def __init__(self, rast): self.rast = rast
def __init__(self, database, context, app_root=None, table='records'): ''' Initialize repository ''' self.context = context # Don't use relative paths, this is hack to get around # most wsgi restriction... if (app_root and database.startswith('sqlite:///') and not database.startswith('sqlite:////')): database = database.replace('sqlite:///', 'sqlite:///%s%s' % (app_root, os.sep)) self.engine = create_engine('%s' % database, echo=False) base = declarative_base(bind=self.engine) LOGGER.debug('binding ORM to existing database') self.postgis_geometry_column = None self.dataset = type('dataset', (base,), dict(__tablename__=table,__table_args__={'autoload': True})) self.dbtype = self.engine.name self.session = create_session(self.engine) temp_dbtype = None # check if PostgreSQL is enabled with PostGIS 1.x if self.dbtype == 'postgresql': try: self.session.execute(select([func.postgis_version()])) temp_dbtype = 'postgresql+postgis+wkt' #LOGGER.debug('PostgreSQL+PostGIS1+WKT detected') except: pass # check if PostgreSQL is enabled with PostGIS 2.x if self.dbtype == 'postgresql': try: self.session.execute('select(postgis_version())') temp_dbtype = 'postgresql+postgis+wkt' #LOGGER.debug('PostgreSQL+PostGIS2+WKT detected') except: pass # check if a native PostGIS geometry column exists if self.dbtype == 'postgresql': try: result = self.session.execute("select f_geometry_column from geometry_columns where f_table_name = '%s' and f_geometry_column != 'wkt_geometry' limit 1;" % table) row = result.fetchone() self.postgis_geometry_column = str(row['f_geometry_column']) temp_dbtype = 'postgresql+postgis+native' #LOGGER.debug('PostgreSQL+PostGIS+Native detected') except: pass if temp_dbtype is not None: LOGGER.debug('%s support detected' % temp_dbtype) self.dbtype = temp_dbtype if self.dbtype in ['sqlite', 'sqlite3']: # load SQLite query bindings if __version__ >= '0.7': from sqlalchemy import event @event.listens_for(self.engine, "connect") def connect(dbapi_connection, connection_rec): dbapi_connection.create_function( 'query_spatial', 4, util.query_spatial) dbapi_connection.create_function( 'update_xpath', 3, util.update_xpath) dbapi_connection.create_function('get_anytext', 1, util.get_anytext) dbapi_connection.create_function('get_geometry_area', 1, util.get_geometry_area) dbapi_connection.create_function('get_spatial_overlay_rank', 2, util.get_spatial_overlay_rank) else: # <= 0.6 behaviour self.connection = self.engine.raw_connection() self.connection.create_function( 'query_spatial', 4, util.query_spatial) self.connection.create_function( 'update_xpath', 3, util.update_xpath) self.connection.create_function('get_anytext', 1, util.get_anytext) self.connection.create_function('get_geometry_area', 1, util.get_geometry_area) self.connection.create_function('get_spatial_overlay_rank', 2, util.get_spatial_overlay_rank) LOGGER.debug('setting repository queryables') # generate core queryables db and obj bindings self.queryables = {} for tname in self.context.model['typenames']: for qname in self.context.model['typenames'][tname]['queryables']: self.queryables[qname] = {} for qkey, qvalue in \ self.context.model['typenames'][tname]['queryables'][qname].iteritems(): self.queryables[qname][qkey] = qvalue # flatten all queryables # TODO smarter way of doing this self.queryables['_all'] = {} for qbl in self.queryables: self.queryables['_all'].update(self.queryables[qbl]) self.queryables['_all'].update(self.context.md_core_model['mappings'])
def __init__(self, database, context, app_root=None, table='records'): ''' Initialize repository ''' self.context = context # Don't use relative paths, this is hack to get around # most wsgi restriction... if (app_root and database.startswith('sqlite:///') and not database.startswith('sqlite:////')): database = database.replace('sqlite:///', 'sqlite:///%s%s' % (app_root, os.sep)) engine = create_engine('%s' % database, echo=False) base = declarative_base(bind=engine) LOGGER.debug('binding ORM to existing database') self.dataset = type('dataset', (base,), dict(__tablename__=table,__table_args__={'autoload': True})) self.dbtype = engine.name self.session = create_session(engine) # check if PostgreSQL is enabled with PostGIS if self.dbtype == 'postgresql': try: self.session.execute(select([func.postgis_version()])) self.dbtype = 'postgresql+postgis' LOGGER.debug('PostgreSQL+PostGIS detected') except: pass if self.dbtype in ['sqlite', 'sqlite3']: # load SQLite query bindings if __version__ >= '0.7': from sqlalchemy import event @event.listens_for(engine, "connect") def connect(dbapi_connection, connection_rec): dbapi_connection.create_function( 'query_spatial', 4, util.query_spatial) dbapi_connection.create_function( 'update_xpath', 3, util.update_xpath) dbapi_connection.create_function('get_anytext', 1, util.get_anytext) dbapi_connection.create_function('get_geometry_area', 1, util.get_geometry_area) else: # <= 0.6 behaviour self.connection = engine.raw_connection() self.connection.create_function( 'query_spatial', 4, util.query_spatial) self.connection.create_function( 'update_xpath', 3, util.update_xpath) self.connection.create_function('get_anytext', 1, util.get_anytext) self.connection.create_function('get_geometry_area', 1, util.get_geometry_area) LOGGER.debug('setting repository queryables') # generate core queryables db and obj bindings self.queryables = {} for tname in self.context.model['typenames']: for qname in self.context.model['typenames'][tname]['queryables']: self.queryables[qname] = {} for qkey, qvalue in \ self.context.model['typenames'][tname]['queryables'][qname].iteritems(): self.queryables[qname][qkey] = qvalue # flatten all queryables # TODO smarter way of doing this self.queryables['_all'] = {} for qbl in self.queryables: self.queryables['_all'].update(self.queryables[qbl]) self.queryables['_all'].update(self.context.md_core_model['mappings'])
def __init__(self, database, context, app_root=None, table="records"): """ Initialize repository """ self.context = context # Don't use relative paths, this is hack to get around # most wsgi restriction... if app_root and database.startswith("sqlite:///") and not database.startswith("sqlite:////"): database = database.replace("sqlite:///", "sqlite:///%s%s" % (app_root, os.sep)) self.engine = create_engine("%s" % database, echo=False) base = declarative_base(bind=self.engine) LOGGER.debug("binding ORM to existing database") self.postgis_geometry_column = None self.dataset = type("dataset", (base,), dict(__tablename__=table, __table_args__={"autoload": True})) self.dbtype = self.engine.name self.session = create_session(self.engine) temp_dbtype = None # check if PostgreSQL is enabled with PostGIS 1.x if self.dbtype == "postgresql": try: self.session.execute(select([func.postgis_version()])) temp_dbtype = "postgresql+postgis+wkt" # LOGGER.debug('PostgreSQL+PostGIS1+WKT detected') except: pass # check if PostgreSQL is enabled with PostGIS 2.x if self.dbtype == "postgresql": try: self.session.execute("select(postgis_version())") temp_dbtype = "postgresql+postgis+wkt" # LOGGER.debug('PostgreSQL+PostGIS2+WKT detected') except: pass # check if a native PostGIS geometry column exists if self.dbtype == "postgresql": try: result = self.session.execute( "select f_geometry_column from geometry_columns where f_table_name = '%s' and f_geometry_column != 'wkt_geometry' limit 1;" % table ) row = result.fetchone() self.postgis_geometry_column = str(row["f_geometry_column"]) temp_dbtype = "postgresql+postgis+native" # LOGGER.debug('PostgreSQL+PostGIS+Native detected') except: pass if temp_dbtype is not None: LOGGER.debug("%s support detected" % temp_dbtype) self.dbtype = temp_dbtype if self.dbtype in ["sqlite", "sqlite3"]: # load SQLite query bindings if __version__ >= "0.7": from sqlalchemy import event @event.listens_for(self.engine, "connect") def connect(dbapi_connection, connection_rec): dbapi_connection.create_function("query_spatial", 4, util.query_spatial) dbapi_connection.create_function("update_xpath", 3, util.update_xpath) dbapi_connection.create_function("get_anytext", 1, util.get_anytext) dbapi_connection.create_function("get_geometry_area", 1, util.get_geometry_area) dbapi_connection.create_function("get_spatial_overlay_rank", 2, util.get_spatial_overlay_rank) else: # <= 0.6 behaviour self.connection = self.engine.raw_connection() self.connection.create_function("query_spatial", 4, util.query_spatial) self.connection.create_function("update_xpath", 3, util.update_xpath) self.connection.create_function("get_anytext", 1, util.get_anytext) self.connection.create_function("get_geometry_area", 1, util.get_geometry_area) self.connection.create_function("get_spatial_overlay_rank", 2, util.get_spatial_overlay_rank) LOGGER.debug("setting repository queryables") # generate core queryables db and obj bindings self.queryables = {} for tname in self.context.model["typenames"]: for qname in self.context.model["typenames"][tname]["queryables"]: self.queryables[qname] = {} for qkey, qvalue in self.context.model["typenames"][tname]["queryables"][qname].iteritems(): self.queryables[qname][qkey] = qvalue # flatten all queryables # TODO smarter way of doing this self.queryables["_all"] = {} for qbl in self.queryables: self.queryables["_all"].update(self.queryables[qbl]) self.queryables["_all"].update(self.context.md_core_model["mappings"])
def __init__(self, database, context, app_root=None, table='records'): ''' Initialize repository ''' self.context = context # Don't use relative paths, this is hack to get around # most wsgi restriction... if (app_root and database.startswith('sqlite:///') and not database.startswith('sqlite:////')): database = database.replace('sqlite:///', 'sqlite:///%s%s' % (app_root, os.sep)) self.engine = create_engine('%s' % database, echo=False) base = declarative_base(bind=self.engine) LOGGER.debug('binding ORM to existing database') self.postgis_geometry_column = None self.dataset = type( 'dataset', (base, ), dict(__tablename__=table, __table_args__={'autoload': True})) self.dbtype = self.engine.name self.session = create_session(self.engine) temp_dbtype = None # check if PostgreSQL is enabled with PostGIS 1.x if self.dbtype == 'postgresql': try: self.session.execute(select([func.postgis_version()])) temp_dbtype = 'postgresql+postgis+wkt' #LOGGER.debug('PostgreSQL+PostGIS1+WKT detected') except: pass # check if PostgreSQL is enabled with PostGIS 2.x if self.dbtype == 'postgresql': try: self.session.execute('select(postgis_version())') temp_dbtype = 'postgresql+postgis+wkt' #LOGGER.debug('PostgreSQL+PostGIS2+WKT detected') except: pass # check if a native PostGIS geometry column exists if self.dbtype == 'postgresql': try: result = self.session.execute( "select f_geometry_column from geometry_columns where f_table_name = '%s' and f_geometry_column != 'wkt_geometry' limit 1;" % table) row = result.fetchone() self.postgis_geometry_column = str(row['f_geometry_column']) temp_dbtype = 'postgresql+postgis+native' #LOGGER.debug('PostgreSQL+PostGIS+Native detected') except: pass if temp_dbtype is not None: LOGGER.debug('%s support detected' % temp_dbtype) self.dbtype = temp_dbtype if self.dbtype in ['sqlite', 'sqlite3']: # load SQLite query bindings if __version__ >= '0.7': from sqlalchemy import event @event.listens_for(self.engine, "connect") def connect(dbapi_connection, connection_rec): dbapi_connection.create_function('query_spatial', 4, util.query_spatial) dbapi_connection.create_function('update_xpath', 3, util.update_xpath) dbapi_connection.create_function('get_anytext', 1, util.get_anytext) dbapi_connection.create_function('get_geometry_area', 1, util.get_geometry_area) dbapi_connection.create_function( 'get_spatial_overlay_rank', 2, util.get_spatial_overlay_rank) else: # <= 0.6 behaviour self.connection = self.engine.raw_connection() self.connection.create_function('query_spatial', 4, util.query_spatial) self.connection.create_function('update_xpath', 3, util.update_xpath) self.connection.create_function('get_anytext', 1, util.get_anytext) self.connection.create_function('get_geometry_area', 1, util.get_geometry_area) self.connection.create_function('get_spatial_overlay_rank', 2, util.get_spatial_overlay_rank) LOGGER.debug('setting repository queryables') # generate core queryables db and obj bindings self.queryables = {} for tname in self.context.model['typenames']: for qname in self.context.model['typenames'][tname]['queryables']: self.queryables[qname] = {} for qkey, qvalue in \ self.context.model['typenames'][tname]['queryables'][qname].iteritems(): self.queryables[qname][qkey] = qvalue # flatten all queryables # TODO smarter way of doing this self.queryables['_all'] = {} for qbl in self.queryables: self.queryables['_all'].update(self.queryables[qbl]) self.queryables['_all'].update(self.context.md_core_model['mappings'])
def main(): setup_logging('development.ini') settings = get_appsettings('development.ini') load_local_settings(settings) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) translation_manager.options.update({ 'locales': settings['available_languages'].split(), 'get_locale_fallback': True }) configure_mappers() postgis_version = DBSession.execute(func.postgis_version()).scalar() if not postgis_version.startswith('2.'): # With PostGIS 1.x the AddGeometryColumn and DropGeometryColumn # management functions should be used. Area.__table__.c.geometry.type.management = True Area.__table__.c.centroid.type.management = True Task.__table__.c.geometry.type.management = True Base.metadata.drop_all(engine) Base.metadata.create_all(engine) with transaction.manager: geometry = '{"type":"Polygon","coordinates":[[[85.31038284301758,27.70731518595052],[85.31089782714842,27.698120147680104],[85.3242015838623,27.69842412827061],[85.323429107666,27.70731518595052],[85.31038284301758,27.70731518595052]]]}' # noqa geometry = geojson.loads(geometry, object_hook=geojson.GeoJSON.to_instance) geometry = shapely.geometry.asShape(geometry) geometry = shape.from_shape(geometry, 4326) area = Area(geometry) DBSession.add(area) license1 = License() license1.name = 'NextView' license1.description = "This data is licensed for use by the US Government (USG) under the NextView (NV) license and copyrighted by Digital Globe or GeoEye. The NV license allows the USG to share the imagery and Literal Imagery Derived Products (LIDP) with entities outside the USG when that entity is working directly with the USG, for the USG, or in a manner that is directly beneficial to the USG. The party receiving the data can only use the imagery or LIDP for the original purpose or only as otherwise agreed to by the USG. The party receiving the data cannot share the imagery or LIDP with a third party without express permission from the USG. At no time should this imagery or LIDP be used for other than USG-related purposes and must not be used for commercial gain. The copyright information should be maintained at all times. Your acceptance of these license terms is implied by your use." # noqa license1.plain_text = "In other words, you may only use NextView imagery linked from this site for digitizing OpenStreetMap data for humanitarian purposes." # noqa DBSession.add(license1) license2 = License() license2.name = 'Astrium/UNOSAT' license2.description = "UNOSAT allow any INTERNET USER to use the IMAGE to develop DERIVATIVE WORKS provided that the INTERNET USER includes the DERIVATIVE WORKS he/she created in the OpenStreetMap database under CC-BY-SA licence (http://creativecommons.org/licenses/by-sa/2.0/) and/or Open Database licence (ODbL: http://www.opendatacommons.org/licenses/odbl/), with the credit of the corresponding PRODUCT conspicuously displayed and written in full, in order to allow any OpenStreetMap database user to have access to and to use the DERIVATIVE WORKS. Except for the foregoing, the END USER and/or the INTERNET USER shall not be entitled to sell, distribute, assign, dispose of, lease, sublicense or transfer, directly or indirectly, any DERIVATIVE WORKS to any third party." # noqa license2.plain_text = "Astrium GEO-Information Services and UNOSAT are allowing access to this imagery for creating information in OpenStreetMap. Other uses are not allowed." # noqa DBSession.add(license2) project = Project('Kathmandu - Map all primary roads and buildings') project.area = area project.short_description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." # noqa project.description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." # noqa project.instructions = "**The detailed instructions**\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." # noqa project.entities_to_map = "primary roads, buildings" project.imagery = "tms[22]:http://hiu-maps.net/hot/1.0.0/kathmandu_flipped/{zoom}/{x}/{y}.png" # noqa project.license = license1 DBSession.add(project) with project.force_locale('fr'): project.name = "Kathmandu - Cartographier les routes et les bâtiments" # noqa project.auto_fill(17)
def main(): setup_logging('development.ini') settings = get_appsettings('development.ini') load_local_settings(settings) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) translation_manager.options.update({ 'locales': settings['available_languages'].split(), 'get_locale_fallback': True }) configure_mappers() postgis_version = DBSession.execute(func.postgis_version()).scalar() if not postgis_version.startswith('2.'): # With PostGIS 1.x the AddGeometryColumn and DropGeometryColumn # management functions should be used. Area.__table__.c.geometry.type.management = True Area.__table__.c.centroid.type.management = True Task.__table__.c.geometry.type.management = True Base.metadata.drop_all(engine) Base.metadata.create_all(engine) with transaction.manager: geometry = '{"type":"Polygon","coordinates":[[[85.31038284301758,27.70731518595052],[85.31089782714842,27.698120147680104],[85.3242015838623,27.69842412827061],[85.323429107666,27.70731518595052],[85.31038284301758,27.70731518595052]]]}' # noqa geometry = geojson.loads(geometry, object_hook=geojson.GeoJSON.to_instance) geometry = shapely.geometry.asShape(geometry) geometry = shape.from_shape(geometry, 4326) area = Area( geometry ) DBSession.add(area) license1 = License() license1.name = 'NextView' license1.description = "This data is licensed for use by the US Government (USG) under the NextView (NV) license and copyrighted by Digital Globe or GeoEye. The NV license allows the USG to share the imagery and Literal Imagery Derived Products (LIDP) with entities outside the USG when that entity is working directly with the USG, for the USG, or in a manner that is directly beneficial to the USG. The party receiving the data can only use the imagery or LIDP for the original purpose or only as otherwise agreed to by the USG. The party receiving the data cannot share the imagery or LIDP with a third party without express permission from the USG. At no time should this imagery or LIDP be used for other than USG-related purposes and must not be used for commercial gain. The copyright information should be maintained at all times. Your acceptance of these license terms is implied by your use." # noqa license1.plain_text = "In other words, you may only use NextView imagery linked from this site for digitizing OpenStreetMap data for humanitarian purposes." # noqa DBSession.add(license1) license2 = License() license2.name = 'Astrium/UNOSAT' license2.description = "UNOSAT allow any INTERNET USER to use the IMAGE to develop DERIVATIVE WORKS provided that the INTERNET USER includes the DERIVATIVE WORKS he/she created in the OpenStreetMap database under CC-BY-SA licence (http://creativecommons.org/licenses/by-sa/2.0/) and/or Open Database licence (ODbL: http://www.opendatacommons.org/licenses/odbl/), with the credit of the corresponding PRODUCT conspicuously displayed and written in full, in order to allow any OpenStreetMap database user to have access to and to use the DERIVATIVE WORKS. Except for the foregoing, the END USER and/or the INTERNET USER shall not be entitled to sell, distribute, assign, dispose of, lease, sublicense or transfer, directly or indirectly, any DERIVATIVE WORKS to any third party." # noqa license2.plain_text = "Astrium GEO-Information Services and UNOSAT are allowing access to this imagery for creating information in OpenStreetMap. Other uses are not allowed." # noqa DBSession.add(license2) project = Project( 'Kathmandu - Map all primary roads and buildings' ) project.area = area project.short_description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." # noqa project.description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." # noqa project.instructions = "**The detailed instructions**\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." # noqa project.entities_to_map = "primary roads, buildings" project.imagery = "tms[22]:http://hiu-maps.net/hot/1.0.0/kathmandu_flipped/{zoom}/{x}/{y}.png" # noqa project.license = license1 DBSession.add(project) with project.force_locale('fr'): project.name = "Kathmandu - Cartographier les routes et les bâtiments" # noqa project.auto_fill(17)
def __init__(self, database, context, app_root=None, table='records'): ''' Initialize repository ''' self.context = context # Don't use relative paths, this is hack to get around # most wsgi restriction... if (app_root and database.startswith('sqlite:///') and not database.startswith('sqlite:////')): database = database.replace('sqlite:///', 'sqlite:///%s%s' % (app_root, os.sep)) engine = create_engine('%s' % database, echo=False) base = declarative_base(bind=engine) self.dataset = type('dataset', (base,), dict(__tablename__=table,__table_args__={'autoload': True})) self.dbtype = engine.name self.session = create_session(engine) # check if PostgreSQL is enabled with PostGIS if self.dbtype == 'postgresql': try: self.session.execute(select([func.postgis_version()])) self.dbtype = 'postgresql+postgis' except: pass if self.dbtype in ['sqlite', 'sqlite3']: # load SQLite query bindings if __version__ >= '0.7': from sqlalchemy import event @event.listens_for(engine, "connect") def connect(dbapi_connection, connection_rec): dbapi_connection.create_function( 'query_spatial', 4, util.query_spatial) dbapi_connection.create_function( 'update_xpath', 3, util.update_xpath) dbapi_connection.create_function('get_anytext', 1, util.get_anytext) dbapi_connection.create_function('get_geometry_area', 1, util.get_geometry_area) else: # <= 0.6 behaviour self.connection = engine.raw_connection() self.connection.create_function( 'query_spatial', 4, util.query_spatial) self.connection.create_function( 'update_xpath', 3, util.update_xpath) self.connection.create_function('get_anytext', 1, util.get_anytext) self.connection.create_function('get_geometry_area', 1, util.get_geometry_area) # generate core queryables db and obj bindings self.queryables = {} for tname in self.context.model['typenames']: for qname in self.context.model['typenames'][tname]['queryables']: self.queryables[qname] = {} for qkey, qvalue in \ self.context.model['typenames'][tname]['queryables'][qname].iteritems(): self.queryables[qname][qkey] = qvalue # flatten all queryables # TODO smarter way of doing this self.queryables['_all'] = {} for qbl in self.queryables: self.queryables['_all'].update(self.queryables[qbl]) self.queryables['_all'].update(self.context.md_core_model['mappings'])