正在显示
60 个修改的文件
包含
2258 行增加
和
394 行删除
| ... | ... | @@ -53,10 +53,10 @@ class Table(db.Model): |
| 53 | 53 | ''' |
| 54 | 54 | 数据表元数据 |
| 55 | 55 | ''' |
| 56 | - __tablename__ = 'dmdms_table' | |
| 56 | + __tablename__ = 'dmap_table' | |
| 57 | 57 | guid = Column(String(256), primary_key=True) |
| 58 | 58 | # 数据源外键 |
| 59 | - database_guid = Column(String(256), ForeignKey('dmdms_database.guid')) | |
| 59 | + database_guid = Column(String(256), ForeignKey('dmap_database.guid')) | |
| 60 | 60 | |
| 61 | 61 | # 点线面123 |
| 62 | 62 | table_type = Column(Integer) |
| ... | ... | @@ -77,7 +77,7 @@ class Table(db.Model): |
| 77 | 77 | is_vacuate=Column(Integer,default=0) |
| 78 | 78 | |
| 79 | 79 | # 目录外键 |
| 80 | - catalog_guid = Column(String(256), ForeignKey('dmdms_catalog.guid')) | |
| 80 | + catalog_guid = Column(String(256), ForeignKey('dmap_catalog.guid')) | |
| 81 | 81 | |
| 82 | 82 | relate_columns = relationship('Columns', backref='relate_table', lazy='dynamic') |
| 83 | 83 | relate_table_vacuates = relationship('TableVacuate', backref='relate_table', lazy='dynamic') |
| ... | ... | @@ -87,12 +87,12 @@ class TableVacuate(db.Model): |
| 87 | 87 | ''' |
| 88 | 88 | sub数据表元数据 |
| 89 | 89 | ''' |
| 90 | - __tablename__ = 'dmdms_table_vacuate' | |
| 90 | + __tablename__ = 'dmap_table_vacuate' | |
| 91 | 91 | guid = Column(String(256), primary_key=True) |
| 92 | 92 | name = Column(String(256)) |
| 93 | 93 | level = Column(Integer) |
| 94 | 94 | pixel_distance = Column(Float) |
| 95 | - table_guid = Column(String(256), ForeignKey('dmdms_table.guid')) | |
| 95 | + table_guid = Column(String(256), ForeignKey('dmap_table.guid')) | |
| 96 | 96 | |
| 97 | 97 | #所在的库 |
| 98 | 98 | connectstr= Column(Text) |
| ... | ... | @@ -101,10 +101,10 @@ class Columns(db.Model): |
| 101 | 101 | ''' |
| 102 | 102 | 数据表的列 |
| 103 | 103 | ''' |
| 104 | - __tablename__ = 'dmdms_column' | |
| 104 | + __tablename__ = 'dmap_column' | |
| 105 | 105 | guid = Column(String(256), primary_key=True) |
| 106 | 106 | # 表外键 |
| 107 | - table_guid= Column(String(256), ForeignKey('dmdms_table.guid')) | |
| 107 | + table_guid= Column(String(256), ForeignKey('dmap_table.guid')) | |
| 108 | 108 | name=Column(String(256)) |
| 109 | 109 | alias = Column(String(256)) |
| 110 | 110 | create_time = Column(DateTime) |
| ... | ... | @@ -114,7 +114,7 @@ class Task(db.Model): |
| 114 | 114 | ''' |
| 115 | 115 | 任务表 |
| 116 | 116 | ''' |
| 117 | - __tablename__ = 'dmdms_task' | |
| 117 | + __tablename__ = 'dmap_task' | |
| 118 | 118 | guid = Column(String(256), primary_key=True) |
| 119 | 119 | name = Column(Text) |
| 120 | 120 | process = Column(Text) |
| ... | ... | @@ -122,9 +122,9 @@ class Task(db.Model): |
| 122 | 122 | update_time = Column(DateTime) |
| 123 | 123 | state = Column(Integer) |
| 124 | 124 | #数据源外键 |
| 125 | - database_guid = Column(String(256), ForeignKey('dmdms_database.guid')) | |
| 125 | + database_guid = Column(String(256), ForeignKey('dmap_database.guid')) | |
| 126 | 126 | #目录外键 |
| 127 | - catalog_guid = Column(String(256), ForeignKey('dmdms_catalog.guid')) | |
| 127 | + catalog_guid = Column(String(256), ForeignKey('dmap_catalog.guid')) | |
| 128 | 128 | #抽稀任务指定表的guid |
| 129 | 129 | table_guid = Column(String(256)) |
| 130 | 130 | #任务类型 |
| ... | ... | @@ -146,10 +146,10 @@ class Process(db.Model): |
| 146 | 146 | ''' |
| 147 | 147 | 过程信息表 |
| 148 | 148 | ''' |
| 149 | - __tablename__ = 'dmdms_process' | |
| 149 | + __tablename__ = 'dmap_process' | |
| 150 | 150 | guid = Column(String(256), primary_key=True) |
| 151 | 151 | # 任务外键 |
| 152 | - task_guid = Column(String(256), ForeignKey('dmdms_task.guid')) | |
| 152 | + task_guid = Column(String(256), ForeignKey('dmap_task.guid')) | |
| 153 | 153 | time = Column(DateTime) |
| 154 | 154 | message = Column(Text) |
| 155 | 155 | |
| ... | ... | @@ -158,9 +158,9 @@ class Catalog(db.Model): |
| 158 | 158 | ''' |
| 159 | 159 | 目录表 |
| 160 | 160 | ''' |
| 161 | - __tablename__ = 'dmdms_catalog' | |
| 161 | + __tablename__ = 'dmap_catalog' | |
| 162 | 162 | guid = Column(String(256), primary_key=True) |
| 163 | - database_guid = Column(String(256), ForeignKey('dmdms_database.guid')) | |
| 163 | + database_guid = Column(String(256), ForeignKey('dmap_database.guid')) | |
| 164 | 164 | pguid = Column(String(256)) |
| 165 | 165 | path = Column(Text) |
| 166 | 166 | name = Column(String(256)) |
| ... | ... | @@ -169,11 +169,12 @@ class Catalog(db.Model): |
| 169 | 169 | relate_tables = relationship('Table', backref='relate_catalog', lazy='dynamic') |
| 170 | 170 | relate_tasks = relationship('Task', backref='relate_catalog', lazy='dynamic') |
| 171 | 171 | |
| 172 | + | |
| 172 | 173 | class Database(db.Model): |
| 173 | 174 | ''' |
| 174 | 175 | 数据源表 |
| 175 | 176 | ''' |
| 176 | - __tablename__ = 'dmdms_database' | |
| 177 | + __tablename__ = 'dmap_database' | |
| 177 | 178 | guid = Column(String(256), primary_key=True) |
| 178 | 179 | name = Column(String(256)) |
| 179 | 180 | alias = Column(String(256)) |
| ... | ... | @@ -194,7 +195,7 @@ class InsertingLayerName(db.Model): |
| 194 | 195 | ''' |
| 195 | 196 | 正在入库的数据 |
| 196 | 197 | ''' |
| 197 | - __tablename__ = 'dmdms_iln' | |
| 198 | + __tablename__ = 'dmap_iln' | |
| 198 | 199 | guid = Column(String(256), primary_key=True) |
| 199 | 200 | task_guid = Column(String(256)) |
| 200 | 201 | name = Column(String(256)) |
| ... | ... | @@ -203,9 +204,9 @@ class InsertingLayerName(db.Model): |
| 203 | 204 | class Service(db.Model): |
| 204 | 205 | ''' |
| 205 | 206 | ''' |
| 206 | - __tablename__ = 'dmdms_service' | |
| 207 | + __tablename__ = 'dmap_service' | |
| 207 | 208 | guid = Column(String(256), primary_key=True) |
| 208 | - name=Column(String(256)) | |
| 209 | + name = Column(String(256)) | |
| 209 | 210 | alias = Column(String(256)) |
| 210 | 211 | #服务状态 |
| 211 | 212 | state= Column(Integer) |
| ... | ... | @@ -216,5 +217,55 @@ class Service(db.Model): |
| 216 | 217 | #服务节点 |
| 217 | 218 | node = Column(Integer) |
| 218 | 219 | #服务缩略图 |
| 219 | - overview = Column(Binary) | |
| 220 | + overview = Column(Text) | |
| 221 | + #服务类型 | |
| 222 | + type = Column(String(256)) | |
| 223 | + #具体服务id | |
| 224 | + service_guid = Column(String(256)) | |
| 225 | + # 目录外键 | |
| 226 | + catalog_guid = Column(String(256), ForeignKey('dmap_service_catalog.guid')) | |
| 220 | 227 | |
| 228 | + | |
| 229 | +class ServiceCatalog(db.Model): | |
| 230 | + ''' | |
| 231 | + 目录表 | |
| 232 | + ''' | |
| 233 | + __tablename__ = 'dmap_service_catalog' | |
| 234 | + guid = Column(String(256), primary_key=True) | |
| 235 | + database_guid = Column(String(256), ForeignKey('dmap_database.guid')) | |
| 236 | + pguid = Column(String(256)) | |
| 237 | + path = Column(Text) | |
| 238 | + name = Column(String(256)) | |
| 239 | + sort = Column(Integer) | |
| 240 | + description = Column(Text) | |
| 241 | + relate_services = relationship('Service', backref='relate_catalog', lazy='dynamic') | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | +class TileScheme(db.Model): | |
| 246 | + ''' | |
| 247 | + 切片方案表 | |
| 248 | + ''' | |
| 249 | + __tablename__ = 'dmap_tile_scheme' | |
| 250 | + guid = Column(String(256), primary_key=True) | |
| 251 | + name = Column(String(256)) | |
| 252 | + alias = Column(String(256)) | |
| 253 | + description = Column(Text) | |
| 254 | + crs = Column(String(256)) | |
| 255 | + crs_wkt = Column(Text) | |
| 256 | + | |
| 257 | + extent = Column(Text) | |
| 258 | + top_left = Column(String(256)) | |
| 259 | + | |
| 260 | + # xmin = Column(Float) | |
| 261 | + # ymin = Column(Float) | |
| 262 | + # xmax = Column(Float) | |
| 263 | + # ymax = Column(Float) | |
| 264 | + # origin_x = Column(Float) | |
| 265 | + # origin_y = Column(Float) | |
| 266 | + | |
| 267 | + levels = Column(Text) | |
| 268 | + dpi = Column(Integer) | |
| 269 | + rows = Column(Integer) | |
| 270 | + cols = Column(Integer) | |
| 271 | + update_time = Column(DateTime) | |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -13,7 +13,7 @@ class User (db.Model): |
| 13 | 13 | ''' |
| 14 | 14 | 用户信息表 |
| 15 | 15 | ''' |
| 16 | - __tablename__ = "dmdms_user" | |
| 16 | + __tablename__ = "dmap_user" | |
| 17 | 17 | id = Column(Integer, primary_key=True) |
| 18 | 18 | username = Column(Text) |
| 19 | 19 | password = Column(Text) |
| ... | ... | @@ -33,28 +33,28 @@ class User (db.Model): |
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | class OAuth2Client(db.Model, OAuth2ClientMixin): |
| 36 | - __tablename__ = 'dmdms_oauth2_client' | |
| 36 | + __tablename__ = 'dmap_oauth2_client' | |
| 37 | 37 | |
| 38 | 38 | id = Column(Integer, primary_key=True) |
| 39 | 39 | user_id = Column( |
| 40 | - Integer, ForeignKey('dmdms_user.id', ondelete='CASCADE')) | |
| 40 | + Integer, ForeignKey('dmap_user.id', ondelete='CASCADE')) | |
| 41 | 41 | user = relationship('User') |
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | class OAuth2AuthorizationCode(db.Model, OAuth2AuthorizationCodeMixin): |
| 45 | - __tablename__ = 'dmdms_oauth2_code' | |
| 45 | + __tablename__ = 'dmap_oauth2_code' | |
| 46 | 46 | |
| 47 | 47 | id = Column(Integer, primary_key=True) |
| 48 | 48 | user_id = Column( |
| 49 | - Integer, ForeignKey('dmdms_user.id', ondelete='CASCADE')) | |
| 49 | + Integer, ForeignKey('dmap_user.id', ondelete='CASCADE')) | |
| 50 | 50 | user = relationship('User') |
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | class OAuth2Token(db.Model, OAuth2TokenMixin): |
| 54 | - __tablename__ = 'dmdms_oauth2_token' | |
| 54 | + __tablename__ = 'dmap_oauth2_token' | |
| 55 | 55 | |
| 56 | 56 | id = Column(Integer, primary_key=True) |
| 57 | 57 | user_id = Column( |
| 58 | - Integer, ForeignKey('dmdms_user.id', ondelete='CASCADE')) | |
| 58 | + Integer, ForeignKey('dmap_user.id', ondelete='CASCADE')) | |
| 59 | 59 | # name = Column(Text) |
| 60 | 60 | user = relationship('User') |
| \ No newline at end of file | ... | ... |
不能预览此文件类型
| 1 | +UTF-8 | |
| \ No newline at end of file | ... | ... |
不能预览此文件类型
| 1 | +GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] | |
| \ No newline at end of file | ... | ... |
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<metadata xml:lang="zh"><Esri><CreaDate>20170418</CreaDate><CreaTime>19355600</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>FALSE</SyncOnce><DataProperties><itemProps><itemName Sync="TRUE">北京县区</itemName><imsContentType Sync="TRUE">002</imsContentType><itemLocation><linkage Sync="TRUE">file://\\4N\E$\Data\北京县区区划\北京县区.shp</linkage><protocol Sync="TRUE">Local Area Network</protocol></itemLocation><nativeExtBox><westBL Sync="TRUE">115.417282</westBL><eastBL Sync="TRUE">117.500126</eastBL><southBL Sync="TRUE">39.438282</southBL><northBL Sync="TRUE">41.059244</northBL><exTypeCode Sync="TRUE">1</exTypeCode></nativeExtBox><itemSize Sync="TRUE">0.270</itemSize></itemProps><coordRef><type Sync="TRUE">Geographic</type><geogcsn Sync="TRUE">GCS_WGS_1984</geogcsn><csUnits Sync="TRUE">Angular Unit: Degree (0.017453)</csUnits><peXml Sync="TRUE"><GeographicCoordinateSystem xsi:type='typens:GeographicCoordinateSystem' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/10.1'><WKT>GEOGCS[&quot;GCS_WGS_1984&quot;,DATUM[&quot;D_WGS_1984&quot;,SPHEROID[&quot;WGS_1984&quot;,6378137.0,298.257223563]],PRIMEM[&quot;Greenwich&quot;,0.0],UNIT[&quot;Degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,4326]]</WKT><XOrigin>-400</XOrigin><YOrigin>-400</YOrigin><XYScale>11258999068426.238</XYScale><ZOrigin>-100000</ZOrigin><ZScale>10000</ZScale><MOrigin>-100000</MOrigin><MScale>10000</MScale><XYTolerance>8.983152841195215e-009</XYTolerance><ZTolerance>0.001</ZTolerance><MTolerance>0.001</MTolerance><HighPrecision>true</HighPrecision><LeftLongitude>-180</LeftLongitude><WKID>4326</WKID><LatestWKID>4326</LatestWKID></GeographicCoordinateSystem></peXml></coordRef></DataProperties><SyncDate>20210316</SyncDate><SyncTime>11462400</SyncTime><ModDate>20210316</ModDate><ModTime>11462400</ModTime></Esri><dataIdInfo><envirDesc Sync="TRUE"> Version 6.2 (Build 9200) ; Esri ArcGIS 10.2.0.3348</envirDesc><dataLang><languageCode value="zho" Sync="TRUE"></languageCode><countryCode value="CHN" Sync="TRUE"></countryCode></dataLang><idCitation><resTitle Sync="TRUE">北京县区</resTitle><presForm><PresFormCd value="005" Sync="TRUE"></PresFormCd></presForm></idCitation><spatRpType><SpatRepTypCd value="001" Sync="TRUE"></SpatRepTypCd></spatRpType><dataExt><geoEle><GeoBndBox esriExtentType="search"><exTypeCode Sync="TRUE">1</exTypeCode><westBL Sync="TRUE">115.417282</westBL><eastBL Sync="TRUE">117.500126</eastBL><northBL Sync="TRUE">41.059244</northBL><southBL Sync="TRUE">39.438282</southBL></GeoBndBox></geoEle></dataExt></dataIdInfo><mdLang><languageCode value="zho" Sync="TRUE"></languageCode><countryCode value="CHN" Sync="TRUE"></countryCode></mdLang><distInfo><distFormat><formatName Sync="TRUE">Shapefile</formatName></distFormat><distTranOps><transSize Sync="TRUE">0.270</transSize></distTranOps></distInfo><mdHrLv><ScopeCd value="005" Sync="TRUE"></ScopeCd></mdHrLv><mdHrLvName Sync="TRUE">dataset</mdHrLvName><refSysInfo><RefSystem><refSysID><identCode code="4326" Sync="TRUE"></identCode><idCodeSpace Sync="TRUE">EPSG</idCodeSpace><idVersion Sync="TRUE">8.1.1</idVersion></refSysID></RefSystem></refSysInfo><spatRepInfo><VectSpatRep><geometObjs Name="北京县区"><geoObjTyp><GeoObjTypCd value="002" Sync="TRUE"></GeoObjTypCd></geoObjTyp><geoObjCnt Sync="TRUE">17</geoObjCnt></geometObjs><topLvl><TopoLevCd value="001" Sync="TRUE"></TopoLevCd></topLvl></VectSpatRep></spatRepInfo><spdoinfo><ptvctinf><esriterm Name="北京县区"><efeatyp Sync="TRUE">Simple</efeatyp><efeageom code="4" Sync="TRUE"></efeageom><esritopo Sync="TRUE">FALSE</esritopo><efeacnt Sync="TRUE">17</efeacnt><spindex Sync="TRUE">TRUE</spindex><linrefer Sync="TRUE">FALSE</linrefer></esriterm></ptvctinf></spdoinfo><eainfo><detailed Name="北京县区"><enttyp><enttypl Sync="TRUE">北京县区</enttypl><enttypt Sync="TRUE">Feature Class</enttypt><enttypc Sync="TRUE">17</enttypc></enttyp><attr><attrlabl Sync="TRUE">FID</attrlabl><attalias Sync="TRUE">FID</attalias><attrtype Sync="TRUE">OID</attrtype><attwidth Sync="TRUE">4</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale><attrdef Sync="TRUE">Internal feature number.</attrdef><attrdefs Sync="TRUE">Esri</attrdefs><attrdomv><udom Sync="TRUE">Sequential unique whole numbers that are automatically generated.</udom></attrdomv></attr><attr><attrlabl Sync="TRUE">OBJECTID</attrlabl><attalias Sync="TRUE">OBJECTID</attalias><attrtype Sync="TRUE">Double</attrtype><attwidth Sync="TRUE">10</attwidth><atprecis Sync="TRUE">10</atprecis><attscale Sync="TRUE">0</attscale><attrdef Sync="TRUE">Internal feature number.</attrdef><attrdefs Sync="TRUE">Esri</attrdefs><attrdomv><udom Sync="TRUE">Sequential unique whole numbers that are automatically generated.</udom></attrdomv></attr><attr><attrlabl Sync="TRUE">Shape</attrlabl><attalias Sync="TRUE">Shape</attalias><attrtype Sync="TRUE">Geometry</attrtype><attwidth Sync="TRUE">0</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale><attrdef Sync="TRUE">Feature geometry.</attrdef><attrdefs Sync="TRUE">Esri</attrdefs><attrdomv><udom Sync="TRUE">Coordinates defining the features.</udom></attrdomv></attr><attr><attrlabl Sync="TRUE">NAME</attrlabl><attalias Sync="TRUE">NAME</attalias><attrtype Sync="TRUE">String</attrtype><attwidth Sync="TRUE">60</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale></attr><attr><attrlabl Sync="TRUE">KIND</attrlabl><attalias Sync="TRUE">KIND</attalias><attrtype Sync="TRUE">String</attrtype><attwidth Sync="TRUE">4</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale></attr><attr><attrlabl Sync="TRUE">Shape_Leng</attrlabl><attalias Sync="TRUE">Shape_Leng</attalias><attrtype Sync="TRUE">Double</attrtype><attwidth Sync="TRUE">19</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale></attr><attr><attrlabl Sync="TRUE">Shape_Area</attrlabl><attalias Sync="TRUE">Shape_Area</attalias><attrtype Sync="TRUE">Double</attrtype><attwidth Sync="TRUE">19</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale><attrdef Sync="TRUE">Area of feature in internal units squared.</attrdef><attrdefs Sync="TRUE">Esri</attrdefs><attrdomv><udom Sync="TRUE">Positive real numbers that are automatically generated.</udom></attrdomv></attr></detailed></eainfo><mdDateSt Sync="TRUE">20210316</mdDateSt><mdChar><CharSetCd value="004" Sync="TRUE"></CharSetCd></mdChar></metadata> | ... | ... |
不能预览此文件类型
| ... | ... | @@ -51,7 +51,7 @@ class Api(ApiTemplate): |
| 51 | 51 | |
| 52 | 52 | else: |
| 53 | 53 | # 保存文件 |
| 54 | - parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | |
| 54 | + parent = os.path.dirname(os.path.realpath(__file__)) | |
| 55 | 55 | dir_path, store_file = FileProcess.save(parent) |
| 56 | 56 | store_path = ZipUtil.unzip(store_file) |
| 57 | 57 | ... | ... |
| ... | ... | @@ -2,11 +2,13 @@ |
| 2 | 2 | #createtime: 2021/1/27 |
| 3 | 3 | #email: nheweijun@sina.com |
| 4 | 4 | |
| 5 | -from app.models import Table,Columns | |
| 5 | +from app.models import Table,Columns,DES | |
| 6 | 6 | |
| 7 | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | 8 | from app.util.component.ModelVisitor import ModelVisitor |
| 9 | - | |
| 9 | +from app.util.component.PGUtil import PGUtil | |
| 10 | +from osgeo.ogr import DataSource,Layer | |
| 11 | +from osgeo.osr import SpatialReference | |
| 10 | 12 | class Api(ApiTemplate): |
| 11 | 13 | api_name = "表信息" |
| 12 | 14 | def process(self): |
| ... | ... | @@ -16,10 +18,21 @@ class Api(ApiTemplate): |
| 16 | 18 | table = Table.query.filter_by(guid=table_guid).one_or_none() |
| 17 | 19 | if not table: |
| 18 | 20 | raise Exception("数据不存在!") |
| 19 | - | |
| 21 | + pg_ds = PGUtil.open_pg_data_source(0,DES.decode(table.relate_database.sqlalchemy_uri)) | |
| 22 | + layer:Layer = pg_ds.GetLayerByName(table.name) | |
| 23 | + append_dict ={"epsg":None,"sr_wkt":None,"sr_proj4":None,"exist":1} | |
| 24 | + if layer: | |
| 25 | + sr:SpatialReference = layer.GetSpatialRef() | |
| 26 | + if sr: | |
| 27 | + append_dict["epsg"] = sr.GetAuthorityCode(None) | |
| 28 | + append_dict["sr_wkt"] = sr.ExportToWkt() | |
| 29 | + append_dict["sr_proj4"] = sr.ExportToProj4() | |
| 30 | + else: | |
| 31 | + append_dict["exist"]=0 | |
| 20 | 32 | columns = table.relate_columns.order_by(Columns.name).all() |
| 21 | 33 | res["data"]=ModelVisitor.table_to_json(table) |
| 22 | 34 | res["data"]["columns"] = ModelVisitor.objects_to_jsonarray(columns) |
| 35 | + res["data"].update(append_dict) | |
| 23 | 36 | res["result"] = True |
| 24 | 37 | |
| 25 | 38 | except Exception as e: | ... | ... |
| ... | ... | @@ -5,18 +5,20 @@ |
| 5 | 5 | |
| 6 | 6 | import datetime |
| 7 | 7 | import traceback |
| 8 | -from app.models import Table, Database, DES,Task,db,TableVacuate | |
| 8 | +from app.models import Table, Database, DES,Task,db,TableVacuate,Process | |
| 9 | 9 | |
| 10 | 10 | from sqlalchemy.engine import ResultProxy |
| 11 | 11 | from app.util.component.ApiTemplate import ApiTemplate |
| 12 | -from app.util.component.PGUtil import PGUtil | |
| 13 | -from app.util.component.EntryDataVacuate import VacuateProcess,ThisTask,Process | |
| 12 | + | |
| 14 | 13 | from app.util.component.StructuredPrint import StructurePrint |
| 15 | 14 | from app.util.component.PGUtil import PGUtil |
| 16 | 15 | import multiprocessing |
| 17 | 16 | import uuid |
| 18 | 17 | import configure |
| 19 | -from osgeo.ogr import DataSource,Layer | |
| 18 | +from osgeo.ogr import DataSource,Layer,Geometry | |
| 19 | +from osgeo import ogr | |
| 20 | +from app.util.component.VacuateConf import VacuateConf | |
| 21 | +from app.util.component.GeometryAdapter import GeometryAdapter | |
| 20 | 22 | |
| 21 | 23 | from .table_vacuate_ref import Api as RefApi |
| 22 | 24 | |
| ... | ... | @@ -139,8 +141,9 @@ class Api(ApiTemplate): |
| 139 | 141 | geo = feature.GetGeometryRef() |
| 140 | 142 | #插入抽稀图层 |
| 141 | 143 | if geo is not None: |
| 142 | - vacuate_process.vacuate(geo) | |
| 144 | + vacuate_process.vacuate(geo,feature) | |
| 143 | 145 | |
| 146 | + vacuate_process.set_vacuate_count() | |
| 144 | 147 | |
| 145 | 148 | #新增 |
| 146 | 149 | if configure.VACUATE_DB_URI: |
| ... | ... | @@ -212,4 +215,221 @@ class Api(ApiTemplate): |
| 212 | 215 | } |
| 213 | 216 | } |
| 214 | 217 | } |
| 215 | - } | |
| \ No newline at end of file | ||
| 218 | + } | |
| 219 | + | |
| 220 | +class VacuateProcess: | |
| 221 | + | |
| 222 | + max_level=0 | |
| 223 | + fill_dict={} | |
| 224 | + vacuate_layers={} | |
| 225 | + vacuate_layers_gridsize={} | |
| 226 | + pg_ds_dict = {} | |
| 227 | + # 图层要素大于5W才抽稀 | |
| 228 | + least_vacuate_count = VacuateConf.least_vacuate_count | |
| 229 | + | |
| 230 | + extent=[] | |
| 231 | + is_spatial=False | |
| 232 | + | |
| 233 | + lonlat_gridsize = VacuateConf.lonlat_gridsize | |
| 234 | + project_gridsize = VacuateConf.project_gridsize | |
| 235 | + | |
| 236 | + # 该抽稀过程使用的grid_size | |
| 237 | + t_grid_size = [] | |
| 238 | + | |
| 239 | + # 该抽稀过程的抽稀网格 | |
| 240 | + this_gridsize=[] | |
| 241 | + | |
| 242 | + | |
| 243 | + def __init__(self,layer:Layer,table_guid, options,sqlalchemy_uri): | |
| 244 | + | |
| 245 | + #是空间图层才初始化 | |
| 246 | + if layer.GetExtent()[0] > 0 or layer.GetExtent()[0] < 0: | |
| 247 | + | |
| 248 | + self.is_spatial=True | |
| 249 | + | |
| 250 | + # 判断需要抽稀多少级 | |
| 251 | + | |
| 252 | + lc = layer.GetFeatureCount() | |
| 253 | + extent = layer.GetExtent() | |
| 254 | + self.extent=extent | |
| 255 | + | |
| 256 | + #判断疏密程度 | |
| 257 | + p_x = (extent[1]-extent[0])/10.0 | |
| 258 | + p_y = (extent[3] - extent[2]) / 10.0 | |
| 259 | + fill_precent=0 | |
| 260 | + StructurePrint.print("判断疏密") | |
| 261 | + for ix in range(10): | |
| 262 | + for iy in range(10): | |
| 263 | + grid_extent = [extent[0]+ix*p_x,extent[0]+ix*p_x+p_x,extent[2]+iy*p_y,extent[2]+iy*p_y+p_y] | |
| 264 | + poly = GeometryAdapter.envelop_2_polygon(grid_extent) | |
| 265 | + | |
| 266 | + layer.SetSpatialFilter(None) | |
| 267 | + layer.SetSpatialFilter(poly) | |
| 268 | + layer.ResetReading() | |
| 269 | + if layer.GetNextFeature(): | |
| 270 | + fill_precent += 1 | |
| 271 | + | |
| 272 | + print(fill_precent) | |
| 273 | + StructurePrint.print("判断疏密结束") | |
| 274 | + | |
| 275 | + layer.SetSpatialFilter(None) | |
| 276 | + layer.ResetReading() | |
| 277 | + # 固有疏密程度 | |
| 278 | + original_density=8 | |
| 279 | + | |
| 280 | + | |
| 281 | + # 额外一层 | |
| 282 | + # self.this_gridsize.append(0.000075) | |
| 283 | + # self.max_level += 1 | |
| 284 | + ###### | |
| 285 | + | |
| 286 | + if extent[0]>180: | |
| 287 | + self.t_grid_size=self.project_gridsize | |
| 288 | + else: | |
| 289 | + self.t_grid_size = self.lonlat_gridsize | |
| 290 | + | |
| 291 | + for grid_size in self.t_grid_size: | |
| 292 | + # 最少抽稀个数 | |
| 293 | + if lc > self.least_vacuate_count: | |
| 294 | + # 网格数至少大于 | |
| 295 | + if ((extent[1] - extent[0]) * (extent[3] - extent[2])) / (grid_size**2)>self.least_vacuate_count: | |
| 296 | + # 要素数量大于网格数量 | |
| 297 | + # 要考虑图层的疏密程度,original_density*(100.0/fill_precent) 为疏密指数 | |
| 298 | + if lc * original_density * (100.0/fill_precent)>((extent[1] - extent[0])*(extent[3] - extent[2]))/(grid_size**2) : | |
| 299 | + print(grid_size) | |
| 300 | + self.this_gridsize.append(grid_size) | |
| 301 | + self.max_level += 1 | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + # 创建抽稀ds | |
| 306 | + for l in range(self.max_level): | |
| 307 | + # pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, DES.decode(sqlalchemy_uri)) | |
| 308 | + if configure.VACUATE_DB_URI: | |
| 309 | + pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, configure.VACUATE_DB_URI) | |
| 310 | + else: | |
| 311 | + pg_ds_l: DataSource = PGUtil.open_pg_data_source(1, DES.decode(sqlalchemy_uri)) | |
| 312 | + pg_ds_l.StartTransaction() | |
| 313 | + self.pg_ds_dict[l] = pg_ds_l | |
| 314 | + | |
| 315 | + # 生成抽稀图层 | |
| 316 | + options = options[1:] | |
| 317 | + options.append("OVERWRITE=yes") | |
| 318 | + options.append("LAUNDER=no") | |
| 319 | + | |
| 320 | + schema = layer.schema | |
| 321 | + # 增加统计字段 | |
| 322 | + schema.append(ogr.FieldDefn("_dcigrid_count_", ogr.OFTInteger)) | |
| 323 | + schema.append(ogr.FieldDefn("_dcigrid_name_", ogr.OFTString)) | |
| 324 | + | |
| 325 | + for l in range(self.max_level): | |
| 326 | + this_grid_len = self.this_gridsize[l] | |
| 327 | + | |
| 328 | + self.vacuate_layers_gridsize[l] = this_grid_len | |
| 329 | + | |
| 330 | + pg = self.pg_ds_dict[l] | |
| 331 | + | |
| 332 | + grid_name = str(this_grid_len) | |
| 333 | + if this_grid_len<1: | |
| 334 | + grid_name = str(this_grid_len).split(".")[-1] | |
| 335 | + if this_grid_len.__eq__(0.00008): | |
| 336 | + grid_name = "00008" | |
| 337 | + | |
| 338 | + # 抽稀图层是点面混合的 | |
| 339 | + # 抽稀表有固定的命名规则 | |
| 340 | + # 抽稀表一定要覆盖 | |
| 341 | + | |
| 342 | + | |
| 343 | + print("{}:{}".format(self.t_grid_size.index(this_grid_len),this_grid_len)) | |
| 344 | + | |
| 345 | + | |
| 346 | + v_ln = "z{}_vacuate_{}_{}".format(table_guid, self.t_grid_size.index(this_grid_len), grid_name) | |
| 347 | + vl = pg.CreateLayer(v_ln, layer.GetSpatialRef(),ogr.wkbUnknown, options) | |
| 348 | + # 抽稀表需要属性 | |
| 349 | + vl.CreateFields(schema) | |
| 350 | + self.vacuate_layers[l] = vl | |
| 351 | + | |
| 352 | + else: | |
| 353 | + pass | |
| 354 | + | |
| 355 | + | |
| 356 | + def vacuate(self,g,feature): | |
| 357 | + | |
| 358 | + if self.is_spatial: | |
| 359 | + | |
| 360 | + # 插入到所有抽稀图层中 | |
| 361 | + for level in range(self.max_level): | |
| 362 | + | |
| 363 | + center: Geometry = g.Centroid() | |
| 364 | + | |
| 365 | + extent = g.GetEnvelope() | |
| 366 | + long_extent= extent[1]-extent[0] | |
| 367 | + lat_extent = extent[3]-extent[2] | |
| 368 | + | |
| 369 | + this_grid_len =self.vacuate_layers_gridsize[level] | |
| 370 | + #超大的直接加入 | |
| 371 | + # if long_extent > 10*this_grid_len or lat_extent >10*this_grid_len: | |
| 372 | + # vacuate_layer: Layer = self.vacuate_layers.get(level) | |
| 373 | + # feat = ogr.Feature(vacuate_layer.GetLayerDefn()) | |
| 374 | + # feat.SetGeometry(g) | |
| 375 | + # vacuate_layer.CreateFeature(feat) | |
| 376 | + # else: | |
| 377 | + | |
| 378 | + row = int((center.GetY() - self.extent[2]) / this_grid_len) | |
| 379 | + col = int((center.GetX() - self.extent[0]) / this_grid_len) | |
| 380 | + key = "{}.{}.{}".format(level, row, col) | |
| 381 | + | |
| 382 | + if not self.fill_dict.get(key): | |
| 383 | + self.fill_dict[key] = 0 | |
| 384 | + if self.fill_dict[key] == 0: | |
| 385 | + | |
| 386 | + vacuate_layer: Layer = self.vacuate_layers.get(level) | |
| 387 | + feat = ogr.Feature(vacuate_layer.GetLayerDefn()) | |
| 388 | + # 如果图形比网格小,直接存储其中心点 | |
| 389 | + if this_grid_len>long_extent and this_grid_len>lat_extent: | |
| 390 | + feat.SetGeometry(center) | |
| 391 | + else: | |
| 392 | + feat.SetGeometry(g) | |
| 393 | + | |
| 394 | + # 复制旧feature属性 | |
| 395 | + field_dict = feature.items() | |
| 396 | + for field_name in field_dict: | |
| 397 | + feat.SetField(field_name, field_dict[field_name]) | |
| 398 | + feat.SetField("_dcigrid_name_",".".join(key.split(".")[1:])) | |
| 399 | + | |
| 400 | + vacuate_layer.CreateFeature(feat) | |
| 401 | + self.fill_dict[key] += 1 | |
| 402 | + #超大的还有机会 | |
| 403 | + elif (long_extent > 10*this_grid_len or lat_extent >10*this_grid_len) and self.fill_dict[key]<5: | |
| 404 | + vacuate_layer: Layer = self.vacuate_layers.get(level) | |
| 405 | + feat = ogr.Feature(vacuate_layer.GetLayerDefn()) | |
| 406 | + feat.SetGeometry(g) | |
| 407 | + | |
| 408 | + # 复制旧feature属性 | |
| 409 | + field_dict = feature.items() | |
| 410 | + for field_name in field_dict: | |
| 411 | + feat.SetField(field_name, field_dict[field_name]) | |
| 412 | + feat.SetField("_dcigrid_name_",".".join(key.split(".")[1:])) | |
| 413 | + | |
| 414 | + vacuate_layer.CreateFeature(feat) | |
| 415 | + self.fill_dict[key] += 1 | |
| 416 | + else: | |
| 417 | + self.fill_dict[key] += 1 | |
| 418 | + | |
| 419 | + def set_vacuate_count(self): | |
| 420 | + if self.is_spatial: | |
| 421 | + # 插入到所有抽稀图层中 | |
| 422 | + for level in range(self.max_level): | |
| 423 | + vacuate_layer: Layer = self.vacuate_layers.get(level) | |
| 424 | + for feat in vacuate_layer: | |
| 425 | + key = "{}.{}".format(level,feat.GetField("_dcigrid_name_")) | |
| 426 | + feat.SetField("_dcigrid_count_",self.fill_dict.get(key)) | |
| 427 | + vacuate_layer.SetFeature(feat) | |
| 428 | + | |
| 429 | + def end(self): | |
| 430 | + for pg in self.pg_ds_dict.values(): | |
| 431 | + pg.Destroy() | |
| 432 | + | |
| 433 | + def rollback(self): | |
| 434 | + for pg in self.pg_ds_dict.values(): | |
| 435 | + pg.RollbackTransaction() | ... | ... |
| ... | ... | @@ -137,7 +137,9 @@ class Api(ApiTemplate): |
| 137 | 137 | geo = feature.GetGeometryRef() |
| 138 | 138 | #插入抽稀图层 |
| 139 | 139 | if geo is not None: |
| 140 | - vacuate_process.vacuate(geo) | |
| 140 | + vacuate_process.vacuate(geo,feature) | |
| 141 | + | |
| 142 | + vacuate_process.set_vacuate_count() | |
| 141 | 143 | |
| 142 | 144 | #删除原有数据 |
| 143 | 145 | for grid in grids: |
| ... | ... | @@ -278,6 +280,12 @@ class VacuateProcess: |
| 278 | 280 | options = options[1:] |
| 279 | 281 | options.append("OVERWRITE=yes") |
| 280 | 282 | options.append("LAUNDER=no") |
| 283 | + | |
| 284 | + schema = layer.schema | |
| 285 | + # 增加统计字段 | |
| 286 | + schema.append(ogr.FieldDefn("_dcigrid_count_", ogr.OFTInteger)) | |
| 287 | + schema.append(ogr.FieldDefn("_dcigrid_name_", ogr.OFTString)) | |
| 288 | + | |
| 281 | 289 | for l in range(self.max_level): |
| 282 | 290 | this_grid_len = self.this_gridsize[l] |
| 283 | 291 | |
| ... | ... | @@ -304,15 +312,16 @@ class VacuateProcess: |
| 304 | 312 | |
| 305 | 313 | v_ln = "z{}_vacuate_{}_{}".format(table_guid,lev, grid_name) |
| 306 | 314 | vl = pg.CreateLayer(v_ln, layer.GetSpatialRef(),ogr.wkbUnknown, options) |
| 315 | + | |
| 307 | 316 | # 抽稀表需要属性 |
| 308 | - vl.CreateFields(layer.schema) | |
| 317 | + vl.CreateFields(schema) | |
| 309 | 318 | self.vacuate_layers[l] = vl |
| 310 | 319 | |
| 311 | 320 | else: |
| 312 | 321 | pass |
| 313 | 322 | |
| 314 | 323 | |
| 315 | - def vacuate(self,g): | |
| 324 | + def vacuate(self,g,feature): | |
| 316 | 325 | |
| 317 | 326 | if self.is_spatial: |
| 318 | 327 | |
| ... | ... | @@ -349,15 +358,42 @@ class VacuateProcess: |
| 349 | 358 | feat.SetGeometry(center) |
| 350 | 359 | else: |
| 351 | 360 | feat.SetGeometry(g) |
| 361 | + | |
| 362 | + # 复制旧feature属性 | |
| 363 | + field_dict = feature.items() | |
| 364 | + for field_name in field_dict: | |
| 365 | + feat.SetField(field_name, field_dict[field_name]) | |
| 366 | + feat.SetField("_dcigrid_name_",".".join(key.split(".")[1:])) | |
| 367 | + | |
| 352 | 368 | vacuate_layer.CreateFeature(feat) |
| 353 | 369 | self.fill_dict[key] += 1 |
| 370 | + | |
| 354 | 371 | #超大的还有机会 |
| 355 | 372 | elif (long_extent > 10*this_grid_len or lat_extent >10*this_grid_len) and self.fill_dict[key]<5: |
| 356 | 373 | vacuate_layer: Layer = self.vacuate_layers.get(level) |
| 357 | 374 | feat = ogr.Feature(vacuate_layer.GetLayerDefn()) |
| 358 | 375 | feat.SetGeometry(g) |
| 376 | + | |
| 377 | + # 复制旧feature属性 | |
| 378 | + field_dict = feature.items() | |
| 379 | + for field_name in field_dict: | |
| 380 | + feat.SetField(field_name, field_dict[field_name]) | |
| 381 | + feat.SetField("_dcigrid_name_",".".join(key.split(".")[1:])) | |
| 382 | + | |
| 359 | 383 | vacuate_layer.CreateFeature(feat) |
| 360 | 384 | self.fill_dict[key] += 1 |
| 385 | + else: | |
| 386 | + self.fill_dict[key] += 1 | |
| 387 | + | |
| 388 | + def set_vacuate_count(self): | |
| 389 | + if self.is_spatial: | |
| 390 | + # 插入到所有抽稀图层中 | |
| 391 | + for level in range(self.max_level): | |
| 392 | + vacuate_layer: Layer = self.vacuate_layers.get(level) | |
| 393 | + for feat in vacuate_layer: | |
| 394 | + key = "{}.{}".format(level,feat.GetField("_dcigrid_name_")) | |
| 395 | + feat.SetField("_dcigrid_count_",self.fill_dict.get(key)) | |
| 396 | + vacuate_layer.SetFeature(feat) | |
| 361 | 397 | |
| 362 | 398 | def end(self): |
| 363 | 399 | for pg in self.pg_ds_dict.values(): | ... | ... |
| ... | ... | @@ -7,9 +7,3 @@ |
| 7 | 7 | from sqlalchemy import Column, Integer, String, ForeignKey, Text, DateTime, Time |
| 8 | 8 | from app.models import db |
| 9 | 9 | |
| 10 | -class TestModel(db.Model): | |
| 11 | - ''' | |
| 12 | - 数据表元数据 | |
| 13 | - ''' | |
| 14 | - __tablename__ = 'test_model' | |
| 15 | - guid = Column(String(256), primary_key=True) | |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -2,3 +2,133 @@ |
| 2 | 2 | #author: 4N |
| 3 | 3 | #createtime: 2021/9/14 |
| 4 | 4 | #email: nheweijun@sina.com |
| 5 | + | |
| 6 | +from flasgger import swag_from | |
| 7 | +from flask import Blueprint | |
| 8 | +from app.util import BlueprintApi | |
| 9 | +from . import service_register | |
| 10 | +from . import service_type | |
| 11 | +from . import service_list | |
| 12 | +from . import service_delete | |
| 13 | +from . import catalog_create | |
| 14 | +from . import catalog_delete | |
| 15 | +from . import catalog_edit | |
| 16 | +from . import catalog_tree | |
| 17 | +from . import catalog_next | |
| 18 | +from . import catalog_real_tree | |
| 19 | +import os | |
| 20 | +from flask import send_from_directory | |
| 21 | + | |
| 22 | + | |
| 23 | +class DataManager(BlueprintApi): | |
| 24 | + | |
| 25 | + bp = Blueprint("Service", __name__, url_prefix="/API/Service") | |
| 26 | + | |
| 27 | + @staticmethod | |
| 28 | + @bp.route('/Register', methods=['POST']) | |
| 29 | + @swag_from(service_register.Api.api_doc) | |
| 30 | + def api_service_register(): | |
| 31 | + """ | |
| 32 | + 服务注册 | |
| 33 | + """ | |
| 34 | + return service_register.Api().result | |
| 35 | + | |
| 36 | + @staticmethod | |
| 37 | + @bp.route('/Type', methods=['GET']) | |
| 38 | + @swag_from(service_type.Api.api_doc) | |
| 39 | + def api_service_type(): | |
| 40 | + """ | |
| 41 | + 可用服务类型 | |
| 42 | + """ | |
| 43 | + return service_type.Api().result | |
| 44 | + | |
| 45 | + @staticmethod | |
| 46 | + @bp.route('/List', methods=['POST']) | |
| 47 | + @swag_from(service_list.Api.api_doc) | |
| 48 | + def api_service_list(): | |
| 49 | + """ | |
| 50 | + 服务列表 | |
| 51 | + """ | |
| 52 | + return service_list.Api().result | |
| 53 | + | |
| 54 | + | |
| 55 | + @staticmethod | |
| 56 | + @bp.route('/Delete', methods=['POST']) | |
| 57 | + @swag_from(service_delete.Api.api_doc) | |
| 58 | + def api_service_delete(): | |
| 59 | + """ | |
| 60 | + 服务删除 | |
| 61 | + """ | |
| 62 | + return service_delete.Api().result | |
| 63 | + | |
| 64 | + @staticmethod | |
| 65 | + @bp.route('/CatalogCreate', methods=['POST']) | |
| 66 | + @swag_from(catalog_create.Api.api_doc) | |
| 67 | + def api_catalog_create(): | |
| 68 | + """ | |
| 69 | + 创建服务目录 | |
| 70 | + """ | |
| 71 | + return catalog_create.Api().result | |
| 72 | + | |
| 73 | + @staticmethod | |
| 74 | + @bp.route('/CatalogDelete', methods=['POST']) | |
| 75 | + @swag_from(catalog_delete.Api.api_doc) | |
| 76 | + def api_catalog_delete(): | |
| 77 | + """ | |
| 78 | + 删除服务目录 | |
| 79 | + """ | |
| 80 | + return catalog_delete.Api().result | |
| 81 | + | |
| 82 | + @staticmethod | |
| 83 | + @bp.route('/CatalogEdit', methods=['POST']) | |
| 84 | + @swag_from(catalog_edit.Api.api_doc) | |
| 85 | + def api_catalog_edit(): | |
| 86 | + """ | |
| 87 | + 修改服务目录 | |
| 88 | + """ | |
| 89 | + return catalog_edit.Api().result | |
| 90 | + | |
| 91 | + @staticmethod | |
| 92 | + @bp.route('/CatalogEdit', methods=['POST']) | |
| 93 | + @swag_from(catalog_edit.Api.api_doc) | |
| 94 | + def api_catalog_edit(): | |
| 95 | + """ | |
| 96 | + 修改服务目录 | |
| 97 | + """ | |
| 98 | + return catalog_edit.Api().result | |
| 99 | + | |
| 100 | + @staticmethod | |
| 101 | + @bp.route('/CatalogNext', methods=['POST']) | |
| 102 | + @swag_from(catalog_next.Api.api_doc) | |
| 103 | + def api_catalog_next(): | |
| 104 | + """ | |
| 105 | + 下一级服务目录 | |
| 106 | + """ | |
| 107 | + return catalog_next.Api().result | |
| 108 | + | |
| 109 | + @staticmethod | |
| 110 | + @bp.route('/CatalogTree', methods=['POST']) | |
| 111 | + @swag_from(catalog_tree.Api.api_doc) | |
| 112 | + def api_catalog_tree(): | |
| 113 | + """ | |
| 114 | + 服务目录树 | |
| 115 | + """ | |
| 116 | + return catalog_tree.Api().result | |
| 117 | + | |
| 118 | + @staticmethod | |
| 119 | + @bp.route('/CatalogRealTree', methods=['POST']) | |
| 120 | + @swag_from(catalog_real_tree.Api.api_doc) | |
| 121 | + def api_catalog_real_tree(): | |
| 122 | + """ | |
| 123 | + 服务目录树 | |
| 124 | + """ | |
| 125 | + return catalog_real_tree.Api().result | |
| 126 | + | |
| 127 | + | |
| 128 | + @staticmethod | |
| 129 | + @bp.route('/Overview/<file>', methods=['GET']) | |
| 130 | + def table_download_file(file): | |
| 131 | + parent = os.path.dirname(os.path.realpath(__file__)) | |
| 132 | + dirpath = os.path.join(parent,"overview") | |
| 133 | + | |
| 134 | + return send_from_directory(dirpath, filename=file, as_attachment=True) | |
| \ No newline at end of file | ... | ... |
app/modules/service/catalog_create.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/3/9 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | +import uuid | |
| 7 | +from app.models import ServiceCatalog,db | |
| 8 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 9 | +class Api(ApiTemplate): | |
| 10 | + api_name = "创建服务目录" | |
| 11 | + | |
| 12 | + | |
| 13 | + def process(self): | |
| 14 | + | |
| 15 | + # 返回结果 | |
| 16 | + res = {} | |
| 17 | + res["result"] = False | |
| 18 | + try: | |
| 19 | + | |
| 20 | + | |
| 21 | + if ServiceCatalog.query.filter_by(name=self.para.get("name"), | |
| 22 | + pguid=self.para.get("pguid"), | |
| 23 | + database_guid=self.para.get("database_guid")).one_or_none(): | |
| 24 | + res["msg"]="目录已经存在!" | |
| 25 | + return res | |
| 26 | + | |
| 27 | + | |
| 28 | + guid = uuid.uuid1().__str__() | |
| 29 | + path = guid | |
| 30 | + | |
| 31 | + # 获得目录的全路径 | |
| 32 | + pguid = self.para.get("pguid") | |
| 33 | + count = 0 | |
| 34 | + while pguid !="0" and count<100: | |
| 35 | + count+=1 | |
| 36 | + path = pguid+":"+path | |
| 37 | + p_catalog = ServiceCatalog.query.filter_by(guid=pguid).one_or_none() | |
| 38 | + pguid = p_catalog.pguid | |
| 39 | + if count==100: | |
| 40 | + raise Exception("目录结构出现问题!") | |
| 41 | + path = "0" + ":" + path | |
| 42 | + | |
| 43 | + sort = ServiceCatalog.query.filter_by(pguid=self.para.get("pguid")).count() | |
| 44 | + | |
| 45 | + catalog = ServiceCatalog(guid=guid, | |
| 46 | + pguid=self.para.get("pguid"),name=self.para.get("name"), | |
| 47 | + sort=sort, | |
| 48 | + description=self.para.get("description"), | |
| 49 | + path=path) | |
| 50 | + db.session.add(catalog) | |
| 51 | + db.session.commit() | |
| 52 | + | |
| 53 | + | |
| 54 | + res["msg"] = "目录创建成功!" | |
| 55 | + res["data"] = guid | |
| 56 | + res["result"] = True | |
| 57 | + except Exception as e: | |
| 58 | + db.session.rollback() | |
| 59 | + raise e | |
| 60 | + return res | |
| 61 | + | |
| 62 | + api_doc={ | |
| 63 | + | |
| 64 | + "tags":["服务接口"], | |
| 65 | + "parameters":[ | |
| 66 | + {"name": "name", | |
| 67 | + "in": "formData", | |
| 68 | + "type": "string", | |
| 69 | + "description":"目录名"}, | |
| 70 | + {"name": "pguid", | |
| 71 | + "in": "formData", | |
| 72 | + "type": "string","description":"父目录guid,创建根目录时为0"} | |
| 73 | + | |
| 74 | + ], | |
| 75 | + "responses":{ | |
| 76 | + 200:{ | |
| 77 | + "schema":{ | |
| 78 | + "properties":{ | |
| 79 | + } | |
| 80 | + } | |
| 81 | + } | |
| 82 | + } | |
| 83 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/catalog_delete.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/3/9 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | +from app.models import ServiceCatalog,db,Service | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | +class Api(ApiTemplate): | |
| 11 | + api_name = "删除目录" | |
| 12 | + def process(self): | |
| 13 | + | |
| 14 | + | |
| 15 | + # 返回结果 | |
| 16 | + res = {} | |
| 17 | + try: | |
| 18 | + # 业务逻辑 | |
| 19 | + | |
| 20 | + | |
| 21 | + catalog_guid = self.para.get("guid") | |
| 22 | + | |
| 23 | + catalog = ServiceCatalog.query.filter_by(guid=catalog_guid).one_or_none() | |
| 24 | + if not catalog: | |
| 25 | + res["msg"]="目录不存在!" | |
| 26 | + return res | |
| 27 | + | |
| 28 | + else: | |
| 29 | + | |
| 30 | + pguid = catalog.pguid | |
| 31 | + # 所有目录 | |
| 32 | + catalogs = ServiceCatalog.query.filter(ServiceCatalog.path.like("%" + catalog_guid + "%")).all() | |
| 33 | + for cata in catalogs: | |
| 34 | + if pguid.__eq__("0"): | |
| 35 | + Service.query.filter_by(catalog_guid=cata.guid).update({"catalog_guid": None}) | |
| 36 | + db.session.delete(cata) | |
| 37 | + else: | |
| 38 | + Service.query.filter_by(catalog_guid=cata.guid).update({"catalog_guid": pguid}) | |
| 39 | + db.session.delete(cata) | |
| 40 | + | |
| 41 | + db.session.commit() | |
| 42 | + res["msg"] = "目录删除成功!" | |
| 43 | + res["result"] = True | |
| 44 | + except Exception as e: | |
| 45 | + db.session.rollback() | |
| 46 | + raise e | |
| 47 | + return res | |
| 48 | + | |
| 49 | + | |
| 50 | + api_doc = { | |
| 51 | + "tags": ["服务接口"], | |
| 52 | + "parameters": [ | |
| 53 | + {"name": "guid", | |
| 54 | + "in": "formData", | |
| 55 | + "type": "string", | |
| 56 | + "description": "目录guid", "required": "true"}, | |
| 57 | + ], | |
| 58 | + "responses": { | |
| 59 | + 200: { | |
| 60 | + "schema": { | |
| 61 | + "properties": { | |
| 62 | + } | |
| 63 | + } | |
| 64 | + } | |
| 65 | + } | |
| 66 | + } | ... | ... |
app/modules/service/catalog_edit.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/3/9 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | +from app.models import ServiceCatalog,db | |
| 7 | + | |
| 8 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 9 | +class Api(ApiTemplate): | |
| 10 | + api_name = "修改目录" | |
| 11 | + def process(self): | |
| 12 | + | |
| 13 | + | |
| 14 | + # 返回结果 | |
| 15 | + res = {} | |
| 16 | + try: | |
| 17 | + # 业务逻辑 | |
| 18 | + if not ServiceCatalog.query.filter_by(guid=self.para.get("guid")).one_or_none(): | |
| 19 | + res["msg"]="目录不存在!" | |
| 20 | + res["result"]=False | |
| 21 | + return res | |
| 22 | + else: | |
| 23 | + if self.para.get("name"): | |
| 24 | + ServiceCatalog.query.filter_by(guid=self.para.get("guid")).update({"name":self.para.get("name")}) | |
| 25 | + if self.para.__contains__("description"): | |
| 26 | + ServiceCatalog.query.filter_by(guid=self.para.get("guid")).update({"description":self.para.get("description")}) | |
| 27 | + db.session.commit() | |
| 28 | + res["msg"] = "目录修改成功!" | |
| 29 | + res["result"] = True | |
| 30 | + except Exception as e: | |
| 31 | + db.session.rollback() | |
| 32 | + raise e | |
| 33 | + return res | |
| 34 | + | |
| 35 | + | |
| 36 | + api_doc = { | |
| 37 | + "tags": ["服务接口"], | |
| 38 | + "parameters": [ | |
| 39 | + {"name": "guid", | |
| 40 | + "in": "formData", | |
| 41 | + "type": "string", | |
| 42 | + "description": "目录guid", "required": "true"}, | |
| 43 | + {"name": "name", | |
| 44 | + "in": "formData", | |
| 45 | + "type": "string", | |
| 46 | + "description": "目录名", "required": "true"} | |
| 47 | + ], | |
| 48 | + "responses": { | |
| 49 | + 200: { | |
| 50 | + "schema": { | |
| 51 | + "properties": { | |
| 52 | + } | |
| 53 | + } | |
| 54 | + } | |
| 55 | + } | |
| 56 | + } | ... | ... |
app/modules/service/catalog_next.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/3/9 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from app.models import ServiceCatalog,db,Service | |
| 8 | + | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | +from app.util.component.ModelVisitor import ModelVisitor | |
| 11 | +class Api(ApiTemplate): | |
| 12 | + api_name = "下一级目录" | |
| 13 | + def process(self): | |
| 14 | + | |
| 15 | + # 返回结果 | |
| 16 | + res = {} | |
| 17 | + try: | |
| 18 | + # 业务逻辑 | |
| 19 | + | |
| 20 | + res["data"] = [] | |
| 21 | + catalogs = ServiceCatalog.query.filter_by(pguid=self.para.get("catalog_guid")).all() | |
| 22 | + for cata in catalogs: | |
| 23 | + catalog_guids = [c.guid for c in ServiceCatalog.query.filter(ServiceCatalog.path.like("%" + cata.guid + "%")).all()] | |
| 24 | + service_count = Service.query.filter(Service.catalog_guid.in_(catalog_guids)).count() | |
| 25 | + cata_json = ModelVisitor.object_to_json(cata) | |
| 26 | + cata_json["service_count"]=service_count | |
| 27 | + res["data"].append(cata_json) | |
| 28 | + res["result"] = True | |
| 29 | + except Exception as e: | |
| 30 | + raise e | |
| 31 | + return res | |
| 32 | + | |
| 33 | + api_doc={ | |
| 34 | + | |
| 35 | + "tags":["服务接口"], | |
| 36 | + "parameters":[ | |
| 37 | + {"name": "catalog_guid", | |
| 38 | + "in": "formData", | |
| 39 | + "type": "string", | |
| 40 | + "description":"目录guid","required": "true"}, | |
| 41 | + {"name": "database_guid", | |
| 42 | + "in": "formData", | |
| 43 | + "type": "string", | |
| 44 | + "description": "数据库guid", "required": "true"}, | |
| 45 | + | |
| 46 | + ], | |
| 47 | + "responses":{ | |
| 48 | + 200:{ | |
| 49 | + "schema":{ | |
| 50 | + "properties":{ | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + } | |
| 55 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/catalog_real_tree.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/3/9 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from app.models import ServiceCatalog,Service | |
| 8 | + | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | +class Api(ApiTemplate): | |
| 11 | + api_name = "目录树" | |
| 12 | + def process(self): | |
| 13 | + | |
| 14 | + # 返回结果 | |
| 15 | + res = {} | |
| 16 | + try: | |
| 17 | + # 业务逻辑 | |
| 18 | + | |
| 19 | + catalogs = ServiceCatalog.query.all() | |
| 20 | + | |
| 21 | + tree_origin = [] | |
| 22 | + for cata in catalogs: | |
| 23 | + catalog_guids = [c.guid for c in ServiceCatalog.query.filter(ServiceCatalog.path.like("%" + cata.guid + "%")).all()] | |
| 24 | + service_count = Service.query.filter(Service.catalog_guid.in_(catalog_guids)).count() | |
| 25 | + | |
| 26 | + cata_json ={} | |
| 27 | + | |
| 28 | + cata_json["description"] = cata.description | |
| 29 | + cata_json["guid"] = cata.guid | |
| 30 | + cata_json["name"] = cata.name | |
| 31 | + cata_json["path"] = cata.path | |
| 32 | + cata_json["pguid"] = cata.pguid | |
| 33 | + cata_json["sort"] = cata.sort | |
| 34 | + cata_json["service_count"]=service_count | |
| 35 | + cata_json["children"] = [] | |
| 36 | + tree_origin.append(cata_json) | |
| 37 | + | |
| 38 | + for cata in tree_origin: | |
| 39 | + cata_pguid = cata["pguid"] | |
| 40 | + if not cata_pguid=="0": | |
| 41 | + for c in tree_origin: | |
| 42 | + if c["guid"].__eq__(cata_pguid): | |
| 43 | + c["children"].append(cata) | |
| 44 | + | |
| 45 | + res["data"] = [cata for cata in tree_origin if cata["pguid"].__eq__("0")] | |
| 46 | + res["result"] = True | |
| 47 | + except Exception as e: | |
| 48 | + raise e | |
| 49 | + return res | |
| 50 | + | |
| 51 | + api_doc={ | |
| 52 | + | |
| 53 | + "tags":["服务接口"], | |
| 54 | + "parameters":[ | |
| 55 | + {"name": "database_guid", | |
| 56 | + "in": "formData", | |
| 57 | + "type": "string", | |
| 58 | + "description": "数据库guid", "required": "true"}, | |
| 59 | + | |
| 60 | + ], | |
| 61 | + "responses":{ | |
| 62 | + 200:{ | |
| 63 | + "schema":{ | |
| 64 | + "properties":{ | |
| 65 | + } | |
| 66 | + } | |
| 67 | + } | |
| 68 | + } | |
| 69 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/catalog_tree.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/3/9 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from app.models import Service,ServiceCatalog,db | |
| 8 | + | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | +class Api(ApiTemplate): | |
| 11 | + api_name = "目录" | |
| 12 | + def process(self): | |
| 13 | + | |
| 14 | + # 返回结果 | |
| 15 | + res = {} | |
| 16 | + try: | |
| 17 | + # 业务逻辑 | |
| 18 | + catalogs = ServiceCatalog.query.all() | |
| 19 | + res["data"]=[] | |
| 20 | + for cata in catalogs: | |
| 21 | + catalog_guids = [c.guid for c in ServiceCatalog.query.filter(ServiceCatalog.path.like("%" + cata.guid + "%")).all()] | |
| 22 | + service_count = Service.query.filter(Service.catalog_guid.in_(catalog_guids)).count() | |
| 23 | + cata_json ={} | |
| 24 | + cata_json["database_guid"]=cata.database_guid | |
| 25 | + cata_json["description"] = cata.description | |
| 26 | + cata_json["guid"] = cata.guid | |
| 27 | + cata_json["name"] = cata.name | |
| 28 | + cata_json["path"] = cata.path | |
| 29 | + cata_json["pguid"] = cata.pguid | |
| 30 | + cata_json["sort"] = cata.sort | |
| 31 | + cata_json["service_count"]=service_count | |
| 32 | + res["data"].append(cata_json) | |
| 33 | + | |
| 34 | + res["result"] = True | |
| 35 | + | |
| 36 | + except Exception as e: | |
| 37 | + raise e | |
| 38 | + return res | |
| 39 | + | |
| 40 | + api_doc={ | |
| 41 | + | |
| 42 | + "tags":["服务接口"], | |
| 43 | + "parameters":[ | |
| 44 | + {"name": "database_guid", | |
| 45 | + "in": "formData", | |
| 46 | + "type": "string", | |
| 47 | + "description": "数据库guid", "required": "true"}, | |
| 48 | + | |
| 49 | + ], | |
| 50 | + "responses":{ | |
| 51 | + 200:{ | |
| 52 | + "schema":{ | |
| 53 | + "properties":{ | |
| 54 | + } | |
| 55 | + } | |
| 56 | + } | |
| 57 | + } | |
| 58 | + } | |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -17,7 +17,7 @@ from . import feature_edit |
| 17 | 17 | class DataManager(BlueprintApi): |
| 18 | 18 | |
| 19 | 19 | bp = Blueprint("FeatureService", __name__, url_prefix="/API/FeatureService") |
| 20 | - | |
| 20 | + service_type = ["要素服务"] | |
| 21 | 21 | @staticmethod |
| 22 | 22 | @bp.route('/Query', methods=['POST']) |
| 23 | 23 | @swag_from(feature_query.Api.api_doc) | ... | ... |
| ... | ... | @@ -17,9 +17,12 @@ from . import image_list |
| 17 | 17 | from . import image_tile |
| 18 | 18 | from . import image_wms |
| 19 | 19 | |
| 20 | + | |
| 21 | + | |
| 20 | 22 | class DataManager(BlueprintApi): |
| 21 | 23 | |
| 22 | - bp = Blueprint("Image", __name__, url_prefix="/API/Image") | |
| 24 | + bp = Blueprint("Image", __name__, url_prefix="/API/Service/Image") | |
| 25 | + service_type = ["影像WMS服务","影像WMTS服务"] | |
| 23 | 26 | |
| 24 | 27 | @staticmethod |
| 25 | 28 | @bp.route('/Register', methods=['POST']) | ... | ... |
| ... | ... | @@ -17,8 +17,8 @@ class Api(ApiTemplate): |
| 17 | 17 | try: |
| 18 | 18 | guid = self.para.get("guid") |
| 19 | 19 | image = Image.query.filter_by(guid=guid).one_or_none() |
| 20 | + db.session.delete(image) | |
| 20 | 21 | db.session.commit() |
| 21 | - # res["data"] = guid | |
| 22 | 22 | res["result"] = True |
| 23 | 23 | |
| 24 | 24 | except Exception as e: |
| ... | ... | @@ -31,8 +31,7 @@ class Api(ApiTemplate): |
| 31 | 31 | "parameters": [ |
| 32 | 32 | {"name": "guid", |
| 33 | 33 | "in": "formData", |
| 34 | - "type": "string", | |
| 35 | - "description": "data_server"} | |
| 34 | + "type": "string"} | |
| 36 | 35 | ], |
| 37 | 36 | "responses": { |
| 38 | 37 | 200: { | ... | ... |
| ... | ... | @@ -47,6 +47,20 @@ class Api(ApiTemplate): |
| 47 | 47 | api_doc = { |
| 48 | 48 | "tags": ["影像接口"], |
| 49 | 49 | "parameters": [ |
| 50 | + {"name": "page_index", | |
| 51 | + "in": "formData", | |
| 52 | + "type": "int", | |
| 53 | + "description": "页"}, | |
| 54 | + {"name": "page_size", | |
| 55 | + "in": "formData", | |
| 56 | + "type": "int", | |
| 57 | + "description": "页大小"}, | |
| 58 | + {"name": "alias", | |
| 59 | + "in": "formData", | |
| 60 | + "type": "string"}, | |
| 61 | + {"name": "name", | |
| 62 | + "in": "formData", | |
| 63 | + "type": "string"}, | |
| 50 | 64 | ], |
| 51 | 65 | "responses": { |
| 52 | 66 | 200: { | ... | ... |
| ... | ... | @@ -6,53 +6,26 @@ |
| 6 | 6 | |
| 7 | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | 8 | from app.util.component.ModelVisitor import ModelVisitor |
| 9 | -from app.modules.service.image.models import ImageService | |
| 10 | -from sqlalchemy import or_ | |
| 11 | 9 | |
| 10 | +from app.modules.service.image.models import Image | |
| 11 | +from sqlalchemy import or_,and_ | |
| 12 | 12 | class Api(ApiTemplate): |
| 13 | 13 | |
| 14 | - | |
| 15 | - | |
| 16 | - api_name = "注册影像服务" | |
| 17 | - | |
| 18 | - | |
| 19 | - | |
| 14 | + api_name = "影像数据预览功能" | |
| 20 | 15 | |
| 21 | 16 | def process(self): |
| 22 | 17 | |
| 23 | - | |
| 24 | - | |
| 25 | 18 | # 返回结果 |
| 26 | 19 | res = {} |
| 27 | - | |
| 28 | 20 | try: |
| 29 | - page_index = int(self.para.get("page_index", "0")) | |
| 30 | - page_size = int(self.para.get("page_size", "10")) | |
| 31 | 21 | |
| 32 | - alias = self.para.get("alias") | |
| 33 | - name = self.para.get("name") | |
| 34 | - | |
| 35 | - image_services = ImageService.query | |
| 36 | - # 并集 | |
| 37 | - if alias and name: | |
| 38 | - image_services = image_services.filter(or_(ImageService.alias.like("%" + alias + "%") , ImageService.name.like("%" + name + "%"))) | |
| 39 | - else: | |
| 40 | - if alias: | |
| 41 | - image_services = image_services.filter(ImageService.alias.like("%" + alias + "%")) | |
| 42 | - if name: | |
| 43 | - image_services = image_services.filter(ImageService.name.like("%" + name + "%")) | |
| 44 | - | |
| 45 | - image_services = image_services.limit(page_size).offset(page_index).all() | |
| 46 | - | |
| 47 | - res["data"] = ModelVisitor.objects_to_jsonarray(image_services) | |
| 48 | 22 | res["result"] = True |
| 49 | - | |
| 50 | - | |
| 51 | 23 | except Exception as e: |
| 52 | 24 | raise e |
| 53 | 25 | |
| 54 | 26 | return res |
| 55 | 27 | |
| 28 | + | |
| 56 | 29 | api_doc = { |
| 57 | 30 | "tags": ["影像接口"], |
| 58 | 31 | "parameters": [ |
| ... | ... | @@ -65,4 +38,6 @@ class Api(ApiTemplate): |
| 65 | 38 | } |
| 66 | 39 | } |
| 67 | 40 | } |
| 68 | - } | |
| \ No newline at end of file | ||
| 41 | + } | |
| 42 | + | |
| 43 | + | ... | ... |
| ... | ... | @@ -53,21 +53,21 @@ class Api(ApiTemplate): |
| 53 | 53 | right_buttom = (geo[0] + geo[1] * image.RasterXSize, geo[3] + geo[5] * image.RasterYSize) |
| 54 | 54 | origin_extent = [left_top[0], right_buttom[0], right_buttom[1], left_top[1]] |
| 55 | 55 | |
| 56 | - target = origin.CloneGeogCS() | |
| 57 | - tran = osr.CoordinateTransformation(origin, target) | |
| 58 | - | |
| 59 | - geo_left_top = tran.TransformPoint(geo[0], geo[3]) | |
| 60 | - geo_right_buttom = tran.TransformPoint(geo[0] + geo[1] * image.RasterXSize, | |
| 61 | - geo[3] + geo[5] * image.RasterYSize) | |
| 62 | - | |
| 63 | - geo_origin_extent = [geo_left_top[1], geo_right_buttom[0], geo_right_buttom[1], geo_left_top[0]] | |
| 56 | + # target = origin.CloneGeogCS() | |
| 57 | + # tran = osr.CoordinateTransformation(origin, target) | |
| 58 | + # | |
| 59 | + # geo_left_top = tran.TransformPoint(geo[0], geo[3]) | |
| 60 | + # geo_right_buttom = tran.TransformPoint(geo[0] + geo[1] * image.RasterXSize, | |
| 61 | + # geo[3] + geo[5] * image.RasterYSize) | |
| 62 | + # | |
| 63 | + # geo_origin_extent = [geo_left_top[1], geo_right_buttom[0], geo_right_buttom[1], geo_left_top[0]] | |
| 64 | 64 | |
| 65 | 65 | info = {"band_count": band_count, |
| 66 | 66 | "overview_count": count, |
| 67 | 67 | "path":image_info["path"], |
| 68 | 68 | "xy_size": [image.RasterXSize, image.RasterYSize], |
| 69 | 69 | "origin_extent": origin_extent, |
| 70 | - "geo_origin_extent": geo_origin_extent, | |
| 70 | + # "geo_origin_extent": geo_origin_extent, | |
| 71 | 71 | "null_value": nodatavalue, |
| 72 | 72 | "size":os.path.getsize(image_info["path"]), |
| 73 | 73 | "sr_wkt": image.GetProjection(), |
| ... | ... | @@ -102,8 +102,6 @@ class Api(ApiTemplate): |
| 102 | 102 | # origin_extent = info["origin_extent"] |
| 103 | 103 | |
| 104 | 104 | |
| 105 | - | |
| 106 | - | |
| 107 | 105 | exist_image = Image.query.filter_by(path=os.path.normpath(info.get("path")), |
| 108 | 106 | size=info.get("size")).one_or_none() |
| 109 | 107 | if exist_image: |
| ... | ... | @@ -120,7 +118,7 @@ class Api(ApiTemplate): |
| 120 | 118 | cell_y_size = abs(info.get("cell_y_size")), |
| 121 | 119 | name=os.path.basename(info.get("path")), |
| 122 | 120 | origin_extent=json.dumps(info["origin_extent"]), |
| 123 | - geo_origin_extent = json.dumps(info["geo_origin_extent"]), | |
| 121 | + # geo_origin_extent = json.dumps(info["geo_origin_extent"]), | |
| 124 | 122 | null_value=info.get("null_value"), |
| 125 | 123 | server=data_server, |
| 126 | 124 | path = os.path.normpath(info.get("path")), | ... | ... |
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/7/19 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | +from app.modules.service.image.models import ImageService,Image | |
| 7 | +from app.models import db | |
| 8 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 9 | +import uuid | |
| 10 | +from app.util.component.SliceScheme import SliceScheme | |
| 11 | +from app.util.component.FileProcess import FileProcess | |
| 12 | +import os | |
| 13 | +import json | |
| 14 | +import datetime | |
| 15 | +class Api(ApiTemplate): | |
| 16 | + | |
| 17 | + api_name = "注册影像服务" | |
| 18 | + | |
| 19 | + def process(self): | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + # 返回结果 | |
| 24 | + res = {} | |
| 25 | + | |
| 26 | + try: | |
| 27 | + | |
| 28 | + res["result"] = True | |
| 29 | + except Exception as e: | |
| 30 | + raise e | |
| 31 | + | |
| 32 | + return res | |
| 33 | + | |
| 34 | + api_doc = { | |
| 35 | + "tags": ["影像接口"], | |
| 36 | + "parameters": [ | |
| 37 | + {"name": "guids", | |
| 38 | + "in": "formData", | |
| 39 | + "type": "string", | |
| 40 | + "description": "影像guids,以英文逗号相隔"}, | |
| 41 | + {"name": "file", | |
| 42 | + "in": "formData", | |
| 43 | + "type": "file", | |
| 44 | + "description": "切片方案"}, | |
| 45 | + ], | |
| 46 | + "responses": { | |
| 47 | + 200: { | |
| 48 | + "schema": { | |
| 49 | + "properties": { | |
| 50 | + } | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + } | |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | #email: nheweijun@sina.com |
| 5 | 5 | |
| 6 | 6 | from app.modules.service.image.models import ImageService,Image |
| 7 | -from app.models import db | |
| 7 | +from app.models import db,Service | |
| 8 | 8 | from app.util.component.ApiTemplate import ApiTemplate |
| 9 | 9 | import uuid |
| 10 | 10 | from app.util.component.SliceScheme import SliceScheme |
| ... | ... | @@ -26,6 +26,8 @@ class Api(ApiTemplate): |
| 26 | 26 | try: |
| 27 | 27 | guids = self.para.get("guids").split(",") |
| 28 | 28 | name = self.para.get("name") |
| 29 | + catalog_guid = self.para.get("catalog_guid") | |
| 30 | + | |
| 29 | 31 | service_guid = uuid.uuid1().__str__() |
| 30 | 32 | |
| 31 | 33 | |
| ... | ... | @@ -33,7 +35,7 @@ class Api(ApiTemplate): |
| 33 | 35 | dir_path, store_file = FileProcess.save(parent) |
| 34 | 36 | scheme = SliceScheme(store_file).parameter |
| 35 | 37 | |
| 36 | - service = ImageService(guid=service_guid, name=name, slice_scheme=json.dumps(scheme), | |
| 38 | + service = ImageService(guid=service_guid, name=name, | |
| 37 | 39 | create_time=datetime.datetime.now()) |
| 38 | 40 | service_exetent = [] |
| 39 | 41 | ... | ... |
| ... | ... | @@ -91,11 +91,8 @@ class Api(ApiTemplate): |
| 91 | 91 | height, width = 256,256 |
| 92 | 92 | |
| 93 | 93 | # 多线程获取分布式数据 |
| 94 | - if abs(extent[0])>180: | |
| 95 | - intersect_image = [im for im in images if self.determin_intersect(json.loads(im.origin_extent),extent)] | |
| 96 | - else: | |
| 97 | - intersect_image = [im for im in images if self.determin_intersect(json.loads(im.geo_origin_extent), extent)] | |
| 98 | 94 | |
| 95 | + intersect_image = [im for im in images if self.determin_intersect(json.loads(im.origin_extent),extent)] | |
| 99 | 96 | |
| 100 | 97 | if len(intersect_image) > 1: |
| 101 | 98 | ... | ... |
| ... | ... | @@ -67,12 +67,10 @@ class Api(ApiTemplate): |
| 67 | 67 | |
| 68 | 68 | bands = [1, 2, 3] |
| 69 | 69 | extent = [float(x) for x in bbox.split(",")] |
| 70 | - extent = [extent[1],extent[0],extent[3],extent[2]] | |
| 70 | + # extent = [extent[1],extent[0],extent[3],extent[2]] | |
| 71 | 71 | |
| 72 | - if abs(extent[0])>180: | |
| 73 | - intersect_image = [im for im in images if self.determin_intersect(json.loads(im.origin_extent),extent)] | |
| 74 | - else: | |
| 75 | - intersect_image = [im for im in images if self.determin_intersect(json.loads(im.geo_origin_extent), extent)] | |
| 72 | + | |
| 73 | + intersect_image = [im for im in images if self.determin_intersect(json.loads(im.origin_extent),extent)] | |
| 76 | 74 | |
| 77 | 75 | if len(intersect_image)>1: |
| 78 | 76 | |
| ... | ... | @@ -141,7 +139,6 @@ class Api(ApiTemplate): |
| 141 | 139 | result["message"] = e.__str__() |
| 142 | 140 | return result |
| 143 | 141 | |
| 144 | - | |
| 145 | 142 | def determine_level(self,xysize,origin_extent,extent,max_level): |
| 146 | 143 | ''' |
| 147 | 144 | 根据范围判断调用金字塔的哪一层 |
| ... | ... | @@ -201,7 +198,7 @@ class Api(ApiTemplate): |
| 201 | 198 | ''' |
| 202 | 199 | thrift_connect = ThriftConnect(image.server) |
| 203 | 200 | t1 = time.time() |
| 204 | - image_extent = image.origin_extent if abs(extent[0])>180 else image.geo_origin_extent | |
| 201 | + image_extent = image.origin_extent | |
| 205 | 202 | |
| 206 | 203 | data = thrift_connect.client.getData(image.path, extent, json.loads(image_extent), bands,width,height) |
| 207 | 204 | |
| ... | ... | @@ -324,7 +321,7 @@ class Api(ApiTemplate): |
| 324 | 321 | def get_capabilities(self,image_service:ImageService): |
| 325 | 322 | |
| 326 | 323 | xml = '''<?xml version="1.0" encoding="utf-8" ?> |
| 327 | - <WMS_Capabilities version="1.3.0"> | |
| 324 | + <WMS_Capabilities version="1.2.0"> | |
| 328 | 325 | <Service> |
| 329 | 326 | <Name>WMS</Name> |
| 330 | 327 | <Title>{service_title}</Title> | ... | ... |
| ... | ... | @@ -13,22 +13,21 @@ class Image(db.Model): |
| 13 | 13 | ''' |
| 14 | 14 | 影像元数据 |
| 15 | 15 | ''' |
| 16 | - __tablename__ = 'dmdms_image' | |
| 16 | + __tablename__ = 'dmap_image' | |
| 17 | 17 | guid = Column(String(256), primary_key=True) |
| 18 | 18 | name = Column(String) |
| 19 | 19 | alias = Column(String) |
| 20 | 20 | raster_y_size = Column(Integer) |
| 21 | 21 | raster_x_size = Column(Integer) |
| 22 | 22 | overview_count = Column(Integer) |
| 23 | - origin_extent = Column(String) | |
| 24 | - geo_origin_extent = Column(String) | |
| 23 | + extent = Column(String) | |
| 24 | + # geo_origin_extent = Column(String) | |
| 25 | 25 | null_value = Column(Integer) |
| 26 | 26 | available = Column(Integer)#影像是否可用,不可用可能在创建金字塔中 |
| 27 | 27 | band_count = Column(Integer) |
| 28 | 28 | path = Column(String) |
| 29 | 29 | server = Column(String) |
| 30 | - # host=Column(String) | |
| 31 | - # port=Column(Integer) | |
| 30 | + | |
| 32 | 31 | size = Column(Float) |
| 33 | 32 | #坐标wkt |
| 34 | 33 | sr_wkt = Column(Text) |
| ... | ... | @@ -42,9 +41,9 @@ class Image(db.Model): |
| 42 | 41 | #年份 |
| 43 | 42 | ym = Column(String(256)) |
| 44 | 43 | |
| 45 | -dmdms_image_rel = db.Table('dmdms_image_rel', | |
| 46 | - Column('image_guid',String, ForeignKey('dmdms_image.guid')), | |
| 47 | - Column('service_guid', String, ForeignKey('dmdms_image_service.guid')) | |
| 44 | +dmap_image_rel = db.Table('dmap_image_rel', | |
| 45 | + Column('image_guid',String, ForeignKey('dmap_image.guid')), | |
| 46 | + Column('service_guid', String, ForeignKey('dmap_image_service.guid')) | |
| 48 | 47 | ) |
| 49 | 48 | |
| 50 | 49 | |
| ... | ... | @@ -53,44 +52,40 @@ class ImageService(db.Model): |
| 53 | 52 | ''' |
| 54 | 53 | 影像服务 |
| 55 | 54 | ''' |
| 56 | - __tablename__ = 'dmdms_image_service' | |
| 55 | + __tablename__ = 'dmap_image_service' | |
| 57 | 56 | guid = Column(String(256), primary_key=True) |
| 58 | - name=Column(String(256)) | |
| 59 | - alias = Column(String(256)) | |
| 60 | - state= Column(Integer) | |
| 61 | - create_time = Column(DateTime) | |
| 62 | - update_time = Column(DateTime) | |
| 63 | - description = Column(Text) | |
| 64 | - slice_scheme = Column(Text) | |
| 57 | + | |
| 58 | + scheme_guid = Column(Text) | |
| 65 | 59 | extent = Column(String(256)) |
| 66 | - node = Column(Integer) | |
| 60 | + # node = Column(Integer) | |
| 67 | 61 | #可视范围geojson |
| 68 | - visual_range = Column(Text) | |
| 69 | - #影像服务缩略图 | |
| 70 | - overview = Column(Binary) | |
| 62 | + visual_region = Column(Text) | |
| 63 | + crs = Column(String(256)) | |
| 64 | + | |
| 65 | + service_guid = Column(String, ForeignKey('dmap_service.guid')) | |
| 71 | 66 | |
| 72 | 67 | images = db.relationship('Image', |
| 73 | - secondary=dmdms_image_rel, | |
| 68 | + secondary=dmap_image_rel, | |
| 74 | 69 | backref='image_services', |
| 75 | 70 | lazy='dynamic' |
| 76 | 71 | ) |
| 77 | 72 | |
| 78 | 73 | |
| 79 | -dmdms_image_tag_rel = db.Table('dmdms_image_tag_rel', | |
| 80 | - Column('image_guid',String, ForeignKey('dmdms_image.guid')), | |
| 81 | - Column('tag_guid', String, ForeignKey('dmdms_image_tag.guid')) | |
| 74 | +dmap_image_tag_rel = db.Table('dmap_image_tag_rel', | |
| 75 | + Column('image_guid',String, ForeignKey('dmap_image.guid')), | |
| 76 | + Column('tag_guid', String, ForeignKey('dmap_image_tag.guid')) | |
| 82 | 77 | ) |
| 83 | 78 | |
| 84 | 79 | class ImageTag(db.Model): |
| 85 | 80 | ''' |
| 86 | 81 | 影像标签 |
| 87 | 82 | ''' |
| 88 | - __tablename__ = 'dmdms_image_tag' | |
| 83 | + __tablename__ = 'dmap_image_tag' | |
| 89 | 84 | guid = Column(String(256), primary_key=True) |
| 90 | 85 | name=Column(String(256)) |
| 91 | 86 | alias = Column(String(256)) |
| 92 | 87 | images = db.relationship('Image', |
| 93 | - secondary=dmdms_image_tag_rel, | |
| 88 | + secondary=dmap_image_tag_rel, | |
| 94 | 89 | backref='image_tags', |
| 95 | 90 | lazy='dynamic' |
| 96 | 91 | ) | ... | ... |
app/modules/service/overview/wmts_tb.png
0 → 100644
149.3 KB
app/modules/service/scheme/__init__.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/16 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from flasgger import swag_from | |
| 8 | +from flask import Blueprint | |
| 9 | +from app.util import BlueprintApi | |
| 10 | + | |
| 11 | +from . import scheme_create | |
| 12 | +from . import scheme_delete | |
| 13 | +from . import scheme_edit | |
| 14 | +from . import scheme_list | |
| 15 | +from . import scheme_resolve | |
| 16 | + | |
| 17 | +class SchemeManager(BlueprintApi): | |
| 18 | + | |
| 19 | + bp = Blueprint("Scheme", __name__, url_prefix="/API/Service/Scheme") | |
| 20 | + | |
| 21 | + @staticmethod | |
| 22 | + @bp.route('/Create', methods=['POST']) | |
| 23 | + @swag_from(scheme_create.Api.api_doc) | |
| 24 | + def api_scheme_create(): | |
| 25 | + """ | |
| 26 | + 创建切片方案 | |
| 27 | + """ | |
| 28 | + return scheme_create.Api().result | |
| 29 | + | |
| 30 | + | |
| 31 | + @staticmethod | |
| 32 | + @bp.route('/Delete', methods=['POST']) | |
| 33 | + @swag_from(scheme_delete.Api.api_doc) | |
| 34 | + def api_scheme_delete(): | |
| 35 | + """ | |
| 36 | + 删除切片方案 | |
| 37 | + """ | |
| 38 | + return scheme_delete.Api().result | |
| 39 | + | |
| 40 | + @staticmethod | |
| 41 | + @bp.route('/Edit', methods=['POST']) | |
| 42 | + @swag_from(scheme_edit.Api.api_doc) | |
| 43 | + def api_scheme_edit(): | |
| 44 | + """ | |
| 45 | + 修改切片方案 | |
| 46 | + """ | |
| 47 | + return scheme_edit.Api().result | |
| 48 | + | |
| 49 | + | |
| 50 | + @staticmethod | |
| 51 | + @bp.route('/List', methods=['POST']) | |
| 52 | + @swag_from(scheme_list.Api.api_doc) | |
| 53 | + def api_scheme_list(): | |
| 54 | + """ | |
| 55 | + 切片方案List | |
| 56 | + """ | |
| 57 | + return scheme_list.Api().result | |
| 58 | + | |
| 59 | + | |
| 60 | + @staticmethod | |
| 61 | + @bp.route('/Resolve', methods=['POST']) | |
| 62 | + @swag_from(scheme_resolve.Api.api_doc) | |
| 63 | + def api_scheme_resolve(): | |
| 64 | + """ | |
| 65 | + 解析切片方案 | |
| 66 | + """ | |
| 67 | + return scheme_resolve.Api().result | |
| \ No newline at end of file | ... | ... |
app/modules/service/scheme/scheme_create.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/16 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +import uuid | |
| 8 | +from app.models import TileScheme,db | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | +import datetime | |
| 11 | +import json | |
| 12 | +class Api(ApiTemplate): | |
| 13 | + api_name = "创建方案" | |
| 14 | + | |
| 15 | + def process(self): | |
| 16 | + | |
| 17 | + # 返回结果 | |
| 18 | + res = {} | |
| 19 | + res["result"] = False | |
| 20 | + try: | |
| 21 | + # 业务逻辑 | |
| 22 | + | |
| 23 | + data = self.para | |
| 24 | + # extent = [float(x) for x in data.get("extent").split(",")] if data.get("extent") else [0,0,0,0] | |
| 25 | + # top_left = [float(x) for x in data.get("top_left").split(",")] if data.get("top_left") else [0, 0] | |
| 26 | + | |
| 27 | + guid = uuid.uuid1().__str__() | |
| 28 | + tile_scheme = TileScheme( | |
| 29 | + guid = guid, | |
| 30 | + name = data.get("name"), | |
| 31 | + alias = data.get("alias"), | |
| 32 | + description = data.get("description"), | |
| 33 | + crs = data.get("crs"), | |
| 34 | + crs_wkt = data.get("crs_wkt"), | |
| 35 | + extent = data.get("extent"), | |
| 36 | + top_left = data.get("top_left"), | |
| 37 | + # ymin = extent[1], | |
| 38 | + # xmax = extent[2], | |
| 39 | + # ymax = extent[3], | |
| 40 | + # origin_x = top_left[0], | |
| 41 | + # origin_y = top_left[1], | |
| 42 | + levels = json.dumps(data.get("levels")), | |
| 43 | + dpi = int(data.get("dpi")), | |
| 44 | + rows = int(data.get("rows")), | |
| 45 | + cols = int(data.get("clos")), | |
| 46 | + update_time = datetime.datetime.now() | |
| 47 | + ) | |
| 48 | + | |
| 49 | + db.session.add(tile_scheme) | |
| 50 | + db.session.commit() | |
| 51 | + res["data"] = guid | |
| 52 | + res["result"] = True | |
| 53 | + except Exception as e: | |
| 54 | + db.session.rollback() | |
| 55 | + raise Exception("参数填写错误!") | |
| 56 | + return res | |
| 57 | + | |
| 58 | + api_doc = { | |
| 59 | + | |
| 60 | + "tags": ["方案接口"], | |
| 61 | + "parameters": [ | |
| 62 | + {"name": "name", | |
| 63 | + "in": "formData", | |
| 64 | + "type": "string"}, | |
| 65 | + {"name": "alias", | |
| 66 | + "in": "formData", | |
| 67 | + "type": "string"}, | |
| 68 | + {"name": "crs", | |
| 69 | + "in": "formData", | |
| 70 | + "type": "string"}, | |
| 71 | + {"name": "crs_wkt", | |
| 72 | + "in": "formData", | |
| 73 | + "type": "string"}, | |
| 74 | + {"name": "extent", | |
| 75 | + "in": "formData", | |
| 76 | + "type": "string"}, | |
| 77 | + {"name": "top_left", | |
| 78 | + "in": "formData", | |
| 79 | + "type": "string"}, | |
| 80 | + {"name": "rows", | |
| 81 | + "in": "formData", | |
| 82 | + "type": "string"}, | |
| 83 | + {"name": "cols", | |
| 84 | + "in": "formData", | |
| 85 | + "type": "string"}, | |
| 86 | + {"name": "dpi", | |
| 87 | + "in": "formData", | |
| 88 | + "type": "string"}, | |
| 89 | + {"name": "levels", | |
| 90 | + "in": "formData", | |
| 91 | + "type": "string"}, | |
| 92 | + | |
| 93 | + ], | |
| 94 | + "responses": { | |
| 95 | + 200: { | |
| 96 | + "schema": { | |
| 97 | + "properties": { | |
| 98 | + } | |
| 99 | + } | |
| 100 | + } | |
| 101 | + } | |
| 102 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/scheme/scheme_delete.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/16 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +import uuid | |
| 8 | +from app.models import TileScheme,db | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | +import datetime | |
| 11 | + | |
| 12 | +class Api(ApiTemplate): | |
| 13 | + api_name = "修改方案" | |
| 14 | + | |
| 15 | + def process(self): | |
| 16 | + | |
| 17 | + # 返回结果 | |
| 18 | + res = {} | |
| 19 | + res["result"] = False | |
| 20 | + try: | |
| 21 | + # 业务逻辑 | |
| 22 | + | |
| 23 | + | |
| 24 | + guid = self.para.get("guid") | |
| 25 | + | |
| 26 | + tile_scheme:TileScheme = TileScheme.query.filter_by(guid=guid).one_or_none() | |
| 27 | + if tile_scheme is None: | |
| 28 | + raise Exception("不存在该切片方案!") | |
| 29 | + db.session.delete(tile_scheme) | |
| 30 | + db.session.commit() | |
| 31 | + | |
| 32 | + res["data"] = guid | |
| 33 | + res["result"] = True | |
| 34 | + except Exception as e: | |
| 35 | + db.session.rollback() | |
| 36 | + | |
| 37 | + return res | |
| 38 | + | |
| 39 | + api_doc = { | |
| 40 | + | |
| 41 | + "tags": ["方案接口"], | |
| 42 | + "parameters": [ | |
| 43 | + {"name": "guid", | |
| 44 | + "in": "formData", | |
| 45 | + "type": "string"} | |
| 46 | + | |
| 47 | + ], | |
| 48 | + "responses": { | |
| 49 | + 200: { | |
| 50 | + "schema": { | |
| 51 | + "properties": { | |
| 52 | + } | |
| 53 | + } | |
| 54 | + } | |
| 55 | + } | |
| 56 | + } | ... | ... |
app/modules/service/scheme/scheme_edit.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/16 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +import uuid | |
| 8 | +from app.models import TileScheme,db | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | +import datetime | |
| 11 | + | |
| 12 | +class Api(ApiTemplate): | |
| 13 | + api_name = "修改方案" | |
| 14 | + | |
| 15 | + def process(self): | |
| 16 | + | |
| 17 | + # 返回结果 | |
| 18 | + res = {} | |
| 19 | + res["result"] = False | |
| 20 | + try: | |
| 21 | + # 业务逻辑 | |
| 22 | + data = self.para | |
| 23 | + | |
| 24 | + guid = data.get("guid") | |
| 25 | + | |
| 26 | + tile_scheme:TileScheme = TileScheme.query.filter_by(guid=guid).one_or_none() | |
| 27 | + if tile_scheme is None: | |
| 28 | + raise Exception("不存在该切片方案!") | |
| 29 | + | |
| 30 | + update_dict = data | |
| 31 | + update_dict["update_time"] = datetime.datetime.now() | |
| 32 | + del update_dict["guid"] | |
| 33 | + | |
| 34 | + tile_scheme.update(update_dict) | |
| 35 | + db.session.commit() | |
| 36 | + | |
| 37 | + res["data"] = guid | |
| 38 | + res["result"] = True | |
| 39 | + except Exception as e: | |
| 40 | + db.session.rollback() | |
| 41 | + raise Exception("参数填写错误!") | |
| 42 | + return res | |
| 43 | + | |
| 44 | + api_doc = { | |
| 45 | + | |
| 46 | + "tags": ["方案接口"], | |
| 47 | + "parameters": [ | |
| 48 | + {"name": "guid", | |
| 49 | + "in": "formData", | |
| 50 | + "type": "string"}, | |
| 51 | + {"name": "name", | |
| 52 | + "in": "formData", | |
| 53 | + "type": "string"}, | |
| 54 | + {"name": "alias", | |
| 55 | + "in": "formData", | |
| 56 | + "type": "string"}, | |
| 57 | + {"name": "crs", | |
| 58 | + "in": "formData", | |
| 59 | + "type": "string"}, | |
| 60 | + {"name": "crs_wkt", | |
| 61 | + "in": "formData", | |
| 62 | + "type": "string"}, | |
| 63 | + {"name": "extent", | |
| 64 | + "in": "formData", | |
| 65 | + "type": "string"}, | |
| 66 | + {"name": "top_left", | |
| 67 | + "in": "formData", | |
| 68 | + "type": "string"}, | |
| 69 | + {"name": "rows", | |
| 70 | + "in": "formData", | |
| 71 | + "type": "string"}, | |
| 72 | + {"name": "cols", | |
| 73 | + "in": "formData", | |
| 74 | + "type": "string"}, | |
| 75 | + {"name": "dpi", | |
| 76 | + "in": "formData", | |
| 77 | + "type": "string"}, | |
| 78 | + {"name": "levels", | |
| 79 | + "in": "formData", | |
| 80 | + "type": "string"}, | |
| 81 | + | |
| 82 | + ], | |
| 83 | + "responses": { | |
| 84 | + 200: { | |
| 85 | + "schema": { | |
| 86 | + "properties": { | |
| 87 | + } | |
| 88 | + } | |
| 89 | + } | |
| 90 | + } | |
| 91 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/scheme/scheme_list.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/16 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +import uuid | |
| 8 | +from app.models import TileScheme,db | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | +from app.util.component.ModelVisitor import ModelVisitor | |
| 11 | +from sqlalchemy import or_ | |
| 12 | +import datetime | |
| 13 | + | |
| 14 | +class Api(ApiTemplate): | |
| 15 | + api_name = "查询切片方案" | |
| 16 | + | |
| 17 | + def process(self): | |
| 18 | + | |
| 19 | + # 返回结果 | |
| 20 | + res = {} | |
| 21 | + res["result"] = False | |
| 22 | + try: | |
| 23 | + # 业务逻辑 | |
| 24 | + | |
| 25 | + page_index = int(self.para.get("page_index", "0")) | |
| 26 | + page_size = int(self.para.get("page_size", "10")) | |
| 27 | + | |
| 28 | + alias = self.para.get("alias") | |
| 29 | + name = self.para.get("name") | |
| 30 | + schemes = TileScheme.query | |
| 31 | + | |
| 32 | + # 并集 | |
| 33 | + if alias and name: | |
| 34 | + schemes = schemes.filter(or_(TileScheme.alias.like("%" + alias + "%") , TileScheme.name.like("%" + name + "%"))) | |
| 35 | + else: | |
| 36 | + if alias: | |
| 37 | + schemes = schemes.filter(TileScheme.alias.like("%" + alias + "%")) | |
| 38 | + if name: | |
| 39 | + schemes = schemes.filter(TileScheme.name.like("%" + name + "%")) | |
| 40 | + | |
| 41 | + schemes = schemes.limit(page_size).offset(page_index).all() | |
| 42 | + | |
| 43 | + res["data"] = ModelVisitor.objects_to_jsonarray(schemes) | |
| 44 | + res["result"] = True | |
| 45 | + | |
| 46 | + except Exception as e: | |
| 47 | + raise e | |
| 48 | + | |
| 49 | + return res | |
| 50 | + | |
| 51 | + api_doc = { | |
| 52 | + | |
| 53 | + "tags": ["方案接口"], | |
| 54 | + "parameters": [ | |
| 55 | + {"name": "page_index", | |
| 56 | + "in": "formData", | |
| 57 | + "type": "int", | |
| 58 | + "description": "页"}, | |
| 59 | + {"name": "page_size", | |
| 60 | + "in": "formData", | |
| 61 | + "type": "int", | |
| 62 | + "description": "页大小"}, | |
| 63 | + {"name": "alias", | |
| 64 | + "in": "formData", | |
| 65 | + "type": "string"}, | |
| 66 | + {"name": "name", | |
| 67 | + "in": "formData", | |
| 68 | + "type": "string"}, | |
| 69 | + | |
| 70 | + ], | |
| 71 | + "responses": { | |
| 72 | + 200: { | |
| 73 | + "schema": { | |
| 74 | + "properties": { | |
| 75 | + } | |
| 76 | + } | |
| 77 | + } | |
| 78 | + } | |
| 79 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/scheme/scheme_resolve.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/16 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 8 | +import os | |
| 9 | +from app.util.component.FileProcess import FileProcess | |
| 10 | +from app.util.component.SliceScheme import SliceScheme | |
| 11 | +import shutil | |
| 12 | +from app.util.component.StructuredPrint import StructurePrint | |
| 13 | +class Api(ApiTemplate): | |
| 14 | + api_name = "解析方案" | |
| 15 | + | |
| 16 | + def process(self): | |
| 17 | + | |
| 18 | + # 返回结果 | |
| 19 | + res = {} | |
| 20 | + store_file = "" | |
| 21 | + try: | |
| 22 | + # 业务逻辑 | |
| 23 | + parent = os.path.dirname(os.path.realpath(__file__)) | |
| 24 | + dir_path, store_file = FileProcess.save(parent) | |
| 25 | + scheme = SliceScheme(store_file) | |
| 26 | + | |
| 27 | + data = { | |
| 28 | + "crs_wkt": scheme.parameter.get("wkt"), | |
| 29 | + "top_left": "{},{}".format(scheme.parameter.get("x"),scheme.parameter.get("y")), | |
| 30 | + "dpi": scheme.parameter.get("dpi"), | |
| 31 | + "rows": scheme.parameter.get("rows"), | |
| 32 | + "cols": scheme.parameter.get("cols"), | |
| 33 | + "levels": scheme.levels | |
| 34 | + } | |
| 35 | + | |
| 36 | + res["data"] = data | |
| 37 | + res["result"] = True | |
| 38 | + except Exception as e: | |
| 39 | + raise e | |
| 40 | + finally: | |
| 41 | + try: | |
| 42 | + file_tmp_path = os.path.join(store_file.split("file_tmp")[0],"file_tmp") | |
| 43 | + dir_path = os.path.dirname(store_file) | |
| 44 | + i=0 | |
| 45 | + while not os.path.dirname(dir_path).__eq__(file_tmp_path) and i<30: | |
| 46 | + dir_path = os.path.dirname(dir_path) | |
| 47 | + i+=1 | |
| 48 | + if i<30: | |
| 49 | + shutil.rmtree(dir_path,True) | |
| 50 | + StructurePrint.print("删除文件成功!") | |
| 51 | + else: | |
| 52 | + raise Exception("找不到文件!") | |
| 53 | + except Exception as e: | |
| 54 | + StructurePrint.print("删除文件失败!","ERROR") | |
| 55 | + return res | |
| 56 | + | |
| 57 | + api_doc = { | |
| 58 | + | |
| 59 | + "tags": ["方案接口"], | |
| 60 | + "parameters": [ | |
| 61 | + {"name": "file", | |
| 62 | + "in": "formData", | |
| 63 | + "type": "file", | |
| 64 | + "description": "切片方案"}, | |
| 65 | + ], | |
| 66 | + "responses": { | |
| 67 | + 200: { | |
| 68 | + "schema": { | |
| 69 | + "properties": { | |
| 70 | + } | |
| 71 | + } | |
| 72 | + } | |
| 73 | + } | |
| 74 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/service_delete.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/14 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 6 | + | |
| 7 | +from app.util import find_class,BlueprintApi | |
| 8 | +from app.models import Service,db | |
| 9 | + | |
| 10 | + | |
| 11 | +class Api(ApiTemplate): | |
| 12 | + api_name = "服务类型" | |
| 13 | + | |
| 14 | + def process(self): | |
| 15 | + | |
| 16 | + # 返回结果 | |
| 17 | + res = {} | |
| 18 | + | |
| 19 | + try: | |
| 20 | + guid = self.para.get("guid") | |
| 21 | + service = Service.query.filter_by(guid=guid).one_or_none() | |
| 22 | + db.session.remove(service) | |
| 23 | + db.session.commit() | |
| 24 | + res["result"] = True | |
| 25 | + except Exception as e: | |
| 26 | + raise e | |
| 27 | + | |
| 28 | + return res | |
| 29 | + | |
| 30 | + api_doc = { | |
| 31 | + "tags": ["服务接口"], | |
| 32 | + "parameters": [ | |
| 33 | + {"name": "guid", | |
| 34 | + "in": "formData", | |
| 35 | + "type": "string", | |
| 36 | + "description": "guid"}, | |
| 37 | + ], | |
| 38 | + "responses": { | |
| 39 | + 200: { | |
| 40 | + "schema": { | |
| 41 | + "properties": { | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | + } | |
| 46 | + } | ... | ... |
app/modules/service/service_edit.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/14 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 10 | + | |
| 11 | +class Api(ApiTemplate): | |
| 12 | + api_name = "修改服务" | |
| 13 | + def process(self): | |
| 14 | + res = {} | |
| 15 | + try: | |
| 16 | + if self.para.get("type").__eq__("影像WMS"): | |
| 17 | + from app.modules.service.image.image_service_edit import Api | |
| 18 | + elif self.para.get("type").__eq__("影像WMTS"): | |
| 19 | + from app.modules.service.image.image_service_edit import Api | |
| 20 | + elif self.para.get("type").__eq__("WMS"): | |
| 21 | + from app.modules.service.wms.wms_edit import Api | |
| 22 | + elif self.para.get("type").__eq__("WMTS"): | |
| 23 | + from app.modules.service.wmts.wmts_edit import Api | |
| 24 | + else: | |
| 25 | + return res | |
| 26 | + api = Api() | |
| 27 | + api.para = self.para | |
| 28 | + res = api.process() | |
| 29 | + | |
| 30 | + except Exception as e: | |
| 31 | + raise e | |
| 32 | + return res | |
| 33 | + | |
| 34 | + | |
| 35 | + api_doc = { | |
| 36 | + "tags": ["服务接口"], | |
| 37 | + "parameters": [ | |
| 38 | + ], | |
| 39 | + "responses": { | |
| 40 | + 200: { | |
| 41 | + "schema": { | |
| 42 | + "properties": { | |
| 43 | + } | |
| 44 | + } | |
| 45 | + } | |
| 46 | + } | |
| 47 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/service_list.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/14 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 8 | +from app.util.component.ModelVisitor import ModelVisitor | |
| 9 | +from app.models import Service | |
| 10 | +from sqlalchemy import or_ | |
| 11 | + | |
| 12 | + | |
| 13 | +class Api(ApiTemplate): | |
| 14 | + api_name = "服务列表" | |
| 15 | + | |
| 16 | + def process(self): | |
| 17 | + | |
| 18 | + # 返回结果 | |
| 19 | + res = {} | |
| 20 | + | |
| 21 | + try: | |
| 22 | + page_index = int(self.para.get("page_index", "0")) | |
| 23 | + page_size = int(self.para.get("page_size", "10")) | |
| 24 | + | |
| 25 | + alias = self.para.get("alias") | |
| 26 | + name = self.para.get("name") | |
| 27 | + type = self.para.get("type") | |
| 28 | + | |
| 29 | + services = Service.query | |
| 30 | + if type: | |
| 31 | + services = services.filter_by(type=type) | |
| 32 | + # 并集 | |
| 33 | + if alias and name: | |
| 34 | + services = services.filter( | |
| 35 | + or_(Service.alias.like("%" + alias + "%"), Service.name.like("%" + name + "%"))) | |
| 36 | + else: | |
| 37 | + if alias: | |
| 38 | + services = services.filter(Service.alias.like("%" + alias + "%")) | |
| 39 | + if name: | |
| 40 | + services = services.filter(Service.name.like("%" + name + "%")) | |
| 41 | + | |
| 42 | + services = services.limit(page_size).offset(page_index).all() | |
| 43 | + | |
| 44 | + res["data"] = ModelVisitor.objects_to_jsonarray(services) | |
| 45 | + res["result"] = True | |
| 46 | + | |
| 47 | + | |
| 48 | + except Exception as e: | |
| 49 | + raise e | |
| 50 | + | |
| 51 | + return res | |
| 52 | + | |
| 53 | + api_doc = { | |
| 54 | + "tags": ["服务接口"], | |
| 55 | + "parameters": [ | |
| 56 | + {"name": "page_index", | |
| 57 | + "in": "formData", | |
| 58 | + "type": "int", | |
| 59 | + "description": "页"}, | |
| 60 | + {"name": "page_size", | |
| 61 | + "in": "formData", | |
| 62 | + "type": "int", | |
| 63 | + "description": "页大小"}, | |
| 64 | + {"name": "alias", | |
| 65 | + "in": "formData", | |
| 66 | + "type": "string", | |
| 67 | + "description": "服务别名"}, | |
| 68 | + {"name": "name", | |
| 69 | + "in": "formData", | |
| 70 | + "type": "string", | |
| 71 | + "description": "服务名"}, | |
| 72 | + {"name": "type", | |
| 73 | + "in": "formData", | |
| 74 | + "type": "string", | |
| 75 | + "description": "服务类型"}, | |
| 76 | + ], | |
| 77 | + "responses": { | |
| 78 | + 200: { | |
| 79 | + "schema": { | |
| 80 | + "properties": { | |
| 81 | + } | |
| 82 | + } | |
| 83 | + } | |
| 84 | + } | |
| 85 | + } | ... | ... |
app/modules/service/service_register.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/14 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 7 | + | |
| 8 | +class Api(ApiTemplate): | |
| 9 | + api_name = "注册服务" | |
| 10 | + def process(self): | |
| 11 | + res = {} | |
| 12 | + try: | |
| 13 | + if self.para.get("type").__eq__("影像WMS"): | |
| 14 | + from app.modules.service.image.image_service_register import Api | |
| 15 | + elif self.para.get("type").__eq__("影像WMTS"): | |
| 16 | + from app.modules.service.image.image_service_register import Api | |
| 17 | + elif self.para.get("type").__eq__("WMS"): | |
| 18 | + from app.modules.service.wms.wms_register import Api | |
| 19 | + elif self.para.get("type").__eq__("WMTS"): | |
| 20 | + from app.modules.service.wmts.wmts_register import Api | |
| 21 | + else: | |
| 22 | + return res | |
| 23 | + api = Api() | |
| 24 | + api.para = self.para | |
| 25 | + res = api.process() | |
| 26 | + except Exception as e: | |
| 27 | + raise e | |
| 28 | + return res | |
| 29 | + | |
| 30 | + | |
| 31 | + api_doc = { | |
| 32 | + "tags": ["服务接口"], | |
| 33 | + "parameters": [ | |
| 34 | + ], | |
| 35 | + "responses": { | |
| 36 | + 200: { | |
| 37 | + "schema": { | |
| 38 | + "properties": { | |
| 39 | + } | |
| 40 | + } | |
| 41 | + } | |
| 42 | + } | |
| 43 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/service_type.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/14 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 9 | +import configure | |
| 10 | +from app.util import find_class,BlueprintApi | |
| 11 | + | |
| 12 | + | |
| 13 | +class Api(ApiTemplate): | |
| 14 | + api_name = "服务类型" | |
| 15 | + | |
| 16 | + def process(self): | |
| 17 | + | |
| 18 | + # 返回结果 | |
| 19 | + res = {} | |
| 20 | + service_types = [] | |
| 21 | + try: | |
| 22 | + for scan in ["app.modules.service"]: | |
| 23 | + for api in find_class(scan, BlueprintApi): | |
| 24 | + service_types.extend(api.service_type) | |
| 25 | + res["data"] = service_types | |
| 26 | + res["result"] = True | |
| 27 | + | |
| 28 | + except Exception as e: | |
| 29 | + raise e | |
| 30 | + | |
| 31 | + return res | |
| 32 | + | |
| 33 | + api_doc = { | |
| 34 | + "tags": ["服务接口"], | |
| 35 | + "parameters": [ | |
| 36 | + ], | |
| 37 | + "responses": { | |
| 38 | + 200: { | |
| 39 | + "schema": { | |
| 40 | + "properties": { | |
| 41 | + } | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | + } | ... | ... |
| ... | ... | @@ -2,3 +2,12 @@ |
| 2 | 2 | #author: 4N |
| 3 | 3 | #createtime: 2021/9/14 |
| 4 | 4 | #email: nheweijun@sina.com |
| 5 | + | |
| 6 | +from flasgger import swag_from | |
| 7 | +from flask import Blueprint | |
| 8 | +from app.util import BlueprintApi | |
| 9 | + | |
| 10 | +class DataManager(BlueprintApi): | |
| 11 | + | |
| 12 | + bp = Blueprint("WMS", __name__, url_prefix="/API/Service/WMS") | |
| 13 | + service_type = ["WMS"] | |
| \ No newline at end of file | ... | ... |
app/modules/service/wms/models/__init__.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/6/11 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from sqlalchemy import Column, Integer, String, ForeignKey, Text, DateTime, Time,Binary,Float | |
| 8 | +from app.models import db | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | +class WMS(db.Model): | |
| 13 | + ''' | |
| 14 | + WMTS元数据 | |
| 15 | + ''' | |
| 16 | + __tablename__ = 'dmdms_wms' | |
| 17 | + | |
| 18 | + guid = Column(String(256), primary_key=True) | |
| 19 | + service = Column(String) | |
| 20 | + #基本信息 | |
| 21 | + status = Column(String) | |
| 22 | + description = Column(String) | |
| 23 | + #厂家 | |
| 24 | + username = Column(String(256)) | |
| 25 | + | |
| 26 | + readonly = Column(String) | |
| 27 | + updatetime = Column(DateTime) | |
| 28 | + sid = Column(Integer) | |
| 29 | + stype = Column(String) | |
| 30 | + ssupply = Column(String) | |
| 31 | + sctime = Column(String) | |
| 32 | + company = Column(String) | |
| 33 | + abstract = Column(String) | |
| 34 | + title = Column(String) | |
| 35 | + thumbnail = Column(String) | |
| 36 | + | |
| 37 | + layer_style = Column(Text) | |
| 38 | + | |
| 39 | + service_guid = Column(String,ForeignKey('dmdms_service.guid')) | |
| \ No newline at end of file | ... | ... |
app/modules/service/wms/wms_register.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/17 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 8 | +import uuid | |
| 9 | +from .models import WMS | |
| 10 | +from app.models import Service,db | |
| 11 | +import datetime | |
| 12 | +import configure | |
| 13 | +class Api(ApiTemplate): | |
| 14 | + | |
| 15 | + api_name = "注册WMTS服务" | |
| 16 | + | |
| 17 | + def process(self): | |
| 18 | + # 返回结果 | |
| 19 | + res = {} | |
| 20 | + | |
| 21 | + try: | |
| 22 | + | |
| 23 | + this_time = datetime.datetime.now() | |
| 24 | + service_guid = uuid.uuid1().__str__() | |
| 25 | + wms_service_guid = uuid.uuid1().__str__() | |
| 26 | + | |
| 27 | + | |
| 28 | + #调用wms服务发布接口 | |
| 29 | + | |
| 30 | + service = Service( | |
| 31 | + guid = service_guid, | |
| 32 | + name = self.para.get("name"), | |
| 33 | + alias = self.para.get("alias"), | |
| 34 | + state = int(self.para.get("state")) if self.para.get("state") else None, | |
| 35 | + create_time = this_time, | |
| 36 | + update_time = this_time, | |
| 37 | + description = self.para.get("description"), | |
| 38 | + #node = Column(Integer), | |
| 39 | + overview = "xxxx", | |
| 40 | + type = self.para.get("service_type"), | |
| 41 | + service_guid = wms_service_guid, | |
| 42 | + catalog_guid = self.para.get("catalog_guid") | |
| 43 | + ) | |
| 44 | + | |
| 45 | + wms = WMS( | |
| 46 | + guid = wms_service_guid, | |
| 47 | + name = self.para.get("name"), | |
| 48 | + status = self.para.get("status"), | |
| 49 | + description=self.para.get("description"), | |
| 50 | + username = self.para.get("username"), | |
| 51 | + readonly = self.para.get("readonly"), | |
| 52 | + updatetime = this_time, | |
| 53 | + sid = int(self.para.get("sid")), | |
| 54 | + stype = self.para.get("stype"), | |
| 55 | + ssupply = self.para.get("ssupply"), | |
| 56 | + sctime = self.para.get("sctime"), | |
| 57 | + company = self.para.get("company"), | |
| 58 | + abstract = self.para.get("abstract"), | |
| 59 | + thumbnail = self.para.get("thumbnail"), | |
| 60 | + layer_style = self.para.get("layer_style"), | |
| 61 | + service_guid = service_guid | |
| 62 | + ) | |
| 63 | + | |
| 64 | + | |
| 65 | + db.session.add(service) | |
| 66 | + db.session.add(wms) | |
| 67 | + db.session.commit() | |
| 68 | + res["data"] = service_guid | |
| 69 | + res["result"] = True | |
| 70 | + except Exception as e: | |
| 71 | + db.session.rollback() | |
| 72 | + raise e | |
| 73 | + return res | |
| 74 | + | |
| 75 | + api_doc = { | |
| 76 | + "tags": ["WMTS接口"], | |
| 77 | + "parameters": [ | |
| 78 | + | |
| 79 | + ], | |
| 80 | + "responses": { | |
| 81 | + 200: { | |
| 82 | + "schema": { | |
| 83 | + "properties": { | |
| 84 | + } | |
| 85 | + } | |
| 86 | + } | |
| 87 | + } | |
| 88 | + } | |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -2,3 +2,35 @@ |
| 2 | 2 | #author: 4N |
| 3 | 3 | #createtime: 2021/9/14 |
| 4 | 4 | #email: nheweijun@sina.com |
| 5 | + | |
| 6 | + | |
| 7 | +from flasgger import swag_from | |
| 8 | +from flask import Blueprint | |
| 9 | +from app.util import BlueprintApi | |
| 10 | +from . import upload_oview | |
| 11 | + | |
| 12 | +import os | |
| 13 | +from flask import send_from_directory | |
| 14 | + | |
| 15 | + | |
| 16 | +class DataManager(BlueprintApi): | |
| 17 | + | |
| 18 | + bp = Blueprint("WMTS", __name__, url_prefix="/API/Service/WMTS") | |
| 19 | + | |
| 20 | + @staticmethod | |
| 21 | + @bp.route('/UploadOverview', methods=['POST']) | |
| 22 | + @swag_from(upload_oview.Api.api_doc) | |
| 23 | + def api_upload_oview(): | |
| 24 | + """ | |
| 25 | + 上传缩略图 | |
| 26 | + """ | |
| 27 | + return upload_oview.Api().result | |
| 28 | + | |
| 29 | + @staticmethod | |
| 30 | + @bp.route('/UploadOverview', methods=['POST']) | |
| 31 | + @swag_from(upload_oview.Api.api_doc) | |
| 32 | + def api_upload_oview(): | |
| 33 | + """ | |
| 34 | + 上传缩略图 | |
| 35 | + """ | |
| 36 | + return upload_oview.Api().result | ... | ... |
app/modules/service/wmts/models/__init__.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/6/11 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from sqlalchemy import Column, Integer, String, ForeignKey, Text, DateTime, Time,Binary,Float | |
| 8 | +from app.models import db | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | +class WMTS(db.Model): | |
| 13 | + ''' | |
| 14 | + WMTS元数据 | |
| 15 | + ''' | |
| 16 | + __tablename__ = 'dmap_wmts' | |
| 17 | + | |
| 18 | + guid = Column(String(256), primary_key=True) | |
| 19 | + | |
| 20 | + #基本信息 | |
| 21 | + name = Column(String) | |
| 22 | + wmts_type = Column(String(256)) | |
| 23 | + #厂家 | |
| 24 | + vendor = Column(String(256)) | |
| 25 | + create_time = Column(DateTime) | |
| 26 | + #坐标系 | |
| 27 | + crs = Column(String(256)) | |
| 28 | + #切片路径 | |
| 29 | + datasource = Column(String) | |
| 30 | + #调用地址 | |
| 31 | + metadata_url = Column(String) | |
| 32 | + #描述 | |
| 33 | + description = Column(String) | |
| 34 | + | |
| 35 | + #图层信息 | |
| 36 | + #图层名 | |
| 37 | + layer_name = Column(String(256)) | |
| 38 | + #图层别名 | |
| 39 | + layer_alias = Column(String(256)) | |
| 40 | + #图层title | |
| 41 | + layer_tile = Column(String(256)) | |
| 42 | + #图层样式 | |
| 43 | + layer_style = Column(String(256)) | |
| 44 | + #图片格式 | |
| 45 | + layer_format = Column(String(256)) | |
| 46 | + #图层范围 | |
| 47 | + layer_extent = Column(String) | |
| 48 | + #图层描述 | |
| 49 | + layer_description = Column(String) | |
| 50 | + | |
| 51 | + scheme_guid = Column(String,ForeignKey('dmap_tile_scheme.guid')) | |
| 52 | + | |
| 53 | + service_guid = Column(String,ForeignKey('dmap_service.guid')) | |
| \ No newline at end of file | ... | ... |
app/modules/service/wmts/upload_oview.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/9/17 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 8 | +import os | |
| 9 | +from app.util.component.FileProcess import FileProcess | |
| 10 | +from app.util.component.SliceScheme import SliceScheme | |
| 11 | +import shutil | |
| 12 | +from app.util.component.StructuredPrint import StructurePrint | |
| 13 | +from flask import request | |
| 14 | +import uuid | |
| 15 | +import configure | |
| 16 | +class Api(ApiTemplate): | |
| 17 | + api_name = "上传缩略图" | |
| 18 | + | |
| 19 | + def process(self): | |
| 20 | + | |
| 21 | + # 返回结果 | |
| 22 | + res = {} | |
| 23 | + try: | |
| 24 | + # 业务逻辑 | |
| 25 | + dir_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),"overview") | |
| 26 | + | |
| 27 | + file = request.files['file'] | |
| 28 | + gid = uuid.uuid1().__str__() | |
| 29 | + | |
| 30 | + filename = file.filename.split('"')[0] | |
| 31 | + store_file = os.path.join(dir_path, "{}{}".format(gid,filename)) | |
| 32 | + file.save(store_file) | |
| 33 | + | |
| 34 | + res["data"] ="http://{}/API/Service/Overview/{}".format( | |
| 35 | + configure.deploy_ip_host, "{}{}".format(gid,filename)) | |
| 36 | + res["result"] = True | |
| 37 | + except Exception as e: | |
| 38 | + raise e | |
| 39 | + return res | |
| 40 | + | |
| 41 | + api_doc = { | |
| 42 | + | |
| 43 | + "tags": ["WMTS接口"], | |
| 44 | + "parameters": [ | |
| 45 | + {"name": "file", | |
| 46 | + "in": "formData", | |
| 47 | + "type": "file", | |
| 48 | + "description": "缩略图"}, | |
| 49 | + ], | |
| 50 | + "responses": { | |
| 51 | + 200: { | |
| 52 | + "schema": { | |
| 53 | + "properties": { | |
| 54 | + } | |
| 55 | + } | |
| 56 | + } | |
| 57 | + } | |
| 58 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/wmts/wmts_edit.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/7/19 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 7 | +import uuid | |
| 8 | +from .models import WMTS | |
| 9 | +from app.models import Service,db | |
| 10 | + | |
| 11 | +import datetime | |
| 12 | +class Api(ApiTemplate): | |
| 13 | + | |
| 14 | + api_name = "修改WMTS服务" | |
| 15 | + | |
| 16 | + def process(self): | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + # 返回结果 | |
| 21 | + res = {} | |
| 22 | + | |
| 23 | + try: | |
| 24 | + guid = self.para.get("guid") | |
| 25 | + service = Service.query.filter_by(guid=guid).one_or_none() | |
| 26 | + this_time = datetime.datetime.now() | |
| 27 | + | |
| 28 | + | |
| 29 | + service_update = {"upate_time":this_time} | |
| 30 | + wmts_update = {"upate_time":this_time} | |
| 31 | + for key in self.para.keys(): | |
| 32 | + if key in ["name","alias","state","description","overview","catalog_guid"]: | |
| 33 | + service_update[key] = self.para.get(key) | |
| 34 | + if key in ["name","wmts_type","vendor","crs","datasource","description", | |
| 35 | + "layer_name","layer_alias","layer_tile","layer_style","layer_format", | |
| 36 | + "layer_extent","layer_description","scheme_guid"]: | |
| 37 | + wmts_update[key] = self.para.get(key) | |
| 38 | + | |
| 39 | + | |
| 40 | + wmts = WMTS.query.filter_by(guid=service.service_guid).one_or_none() | |
| 41 | + | |
| 42 | + service.update(service_update) | |
| 43 | + wmts.update(wmts_update) | |
| 44 | + | |
| 45 | + db.session.commit() | |
| 46 | + | |
| 47 | + res["result"] = True | |
| 48 | + except Exception as e: | |
| 49 | + raise e | |
| 50 | + | |
| 51 | + return res | |
| 52 | + | |
| 53 | + api_doc = { | |
| 54 | + "tags": ["影像接口"], | |
| 55 | + "parameters": [ | |
| 56 | + | |
| 57 | + ], | |
| 58 | + "responses": { | |
| 59 | + 200: { | |
| 60 | + "schema": { | |
| 61 | + "properties": { | |
| 62 | + } | |
| 63 | + } | |
| 64 | + } | |
| 65 | + } | |
| 66 | + } | |
| \ No newline at end of file | ... | ... |
app/modules/service/wmts/wmts_register.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2021/7/19 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | + | |
| 7 | +from app.util.component.ApiTemplate import ApiTemplate | |
| 8 | +import uuid | |
| 9 | +from .models import WMTS | |
| 10 | +from app.models import Service,db | |
| 11 | +import datetime | |
| 12 | +import configure | |
| 13 | +class Api(ApiTemplate): | |
| 14 | + | |
| 15 | + api_name = "注册WMTS服务" | |
| 16 | + | |
| 17 | + def process(self): | |
| 18 | + # 返回结果 | |
| 19 | + res = {} | |
| 20 | + | |
| 21 | + try: | |
| 22 | + | |
| 23 | + this_time = datetime.datetime.now() | |
| 24 | + service_guid = uuid.uuid1().__str__() | |
| 25 | + wmts_service_guid = uuid.uuid1().__str__() | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + service = Service( | |
| 30 | + guid = service_guid, | |
| 31 | + name = self.para.get("name"), | |
| 32 | + alias = self.para.get("alias"), | |
| 33 | + state = int(self.para.get("state")) if self.para.get("state") else None, | |
| 34 | + create_time = this_time, | |
| 35 | + update_time = this_time, | |
| 36 | + description = self.para.get("description"), | |
| 37 | + #node = Column(Integer), | |
| 38 | + overview = "http://{}/API/Service/Overview/{}".format( | |
| 39 | + configure.deploy_ip_host, | |
| 40 | + self.para.get("overview") if self.para.get("overview") else "wmts_tb.png"), | |
| 41 | + type = self.para.get("service_type"), | |
| 42 | + service_guid = wmts_service_guid, | |
| 43 | + catalog_guid = self.para.get("catalog_guid") | |
| 44 | + ) | |
| 45 | + | |
| 46 | + wmts = WMTS( | |
| 47 | + guid = wmts_service_guid, | |
| 48 | + name = self.para.get("name"), | |
| 49 | + wmts_type = self.para.get("wmts_type"), | |
| 50 | + vendor = self.para.get("vendor"), | |
| 51 | + create_time = this_time, | |
| 52 | + crs = self.para.get("crs"), | |
| 53 | + datasource = self.para.get("datasource"), | |
| 54 | + description = self.para.get("description"), | |
| 55 | + layer_name = self.para.get("layer_name"), | |
| 56 | + layer_alias = self.para.get("layer_alias"), | |
| 57 | + layer_tile = self.para.get("layer_title"), | |
| 58 | + layer_style = self.para.get("layer_style"), | |
| 59 | + layer_format = self.para.get("layer_format"), | |
| 60 | + layer_extent = self.para.get("layer_extent"), | |
| 61 | + layer_description = self.para.get("layer_description"), | |
| 62 | + scheme_guid = self.para.get("scheme_guid"), | |
| 63 | + service_guid = service_guid | |
| 64 | + ) | |
| 65 | + | |
| 66 | + | |
| 67 | + #调用WMTS的注册服务接口 | |
| 68 | + | |
| 69 | + | |
| 70 | + db.session.add(service) | |
| 71 | + db.session.add(wmts) | |
| 72 | + db.session.commit() | |
| 73 | + res["data"] = service_guid | |
| 74 | + res["result"] = True | |
| 75 | + except Exception as e: | |
| 76 | + db.session.rollback() | |
| 77 | + raise e | |
| 78 | + return res | |
| 79 | + | |
| 80 | + api_doc = { | |
| 81 | + "tags": ["WMTS接口"], | |
| 82 | + "parameters": [ | |
| 83 | + | |
| 84 | + ], | |
| 85 | + "responses": { | |
| 86 | + 200: { | |
| 87 | + "schema": { | |
| 88 | + "properties": { | |
| 89 | + } | |
| 90 | + } | |
| 91 | + } | |
| 92 | + } | |
| 93 | + } | |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -34,241 +34,3 @@ def find_class(modname, class_name): |
| 34 | 34 | yield obj |
| 35 | 35 | for i in find_class(modname, class_name): |
| 36 | 36 | yield i |
| 37 | - | |
| 38 | -# | |
| 39 | -# | |
| 40 | -# # 从sqlachemy_uri解析出相关信息 | |
| 41 | -# def get_info_from_sqlachemy_uri(uri): | |
| 42 | -# parts = uri.split(":") | |
| 43 | -# user = parts[1][2:] | |
| 44 | -# | |
| 45 | -# password_list = parts[2].split("@") | |
| 46 | -# if password_list.__len__()>2: | |
| 47 | -# password = "@".join(password_list[:-1]) | |
| 48 | -# else: | |
| 49 | -# password = parts[2].split("@")[0] | |
| 50 | -# host = parts[2].split("@")[-1] | |
| 51 | -# port = parts[3].split("/")[0] | |
| 52 | -# database = parts[3].split("/")[1] | |
| 53 | -# return user, password, host, port, database | |
| 54 | -# | |
| 55 | -# | |
| 56 | -# # 获取请求参数 | |
| 57 | -# def get_parameter(): | |
| 58 | -# parameter = {} | |
| 59 | -# parameter.update(request.args.items()) | |
| 60 | -# parameter.update(request.form.items()) | |
| 61 | -# try: | |
| 62 | -# request_json = request.get_json() | |
| 63 | -# if json: | |
| 64 | -# parameter.update(request_json) | |
| 65 | -# except: | |
| 66 | -# pass | |
| 67 | -# for key in parameter.keys(): | |
| 68 | -# if parameter.get(key) == "": | |
| 69 | -# parameter[key] = None | |
| 70 | -# return parameter | |
| 71 | -# | |
| 72 | -# | |
| 73 | -# def togeojson(dict): | |
| 74 | -# geojson = {} | |
| 75 | -# geojson["type"] = "Feature" | |
| 76 | -# geojson["geometry"] = json.loads(dict.pop("geojson")) | |
| 77 | -# del dict["geojson"] | |
| 78 | -# if dict.get("wkb_geometry"): | |
| 79 | -# del dict["wkb_geometry"] | |
| 80 | -# geojson["properties"] = dict | |
| 81 | -# return geojson | |
| 82 | -# | |
| 83 | -# | |
| 84 | -# def to_feature_collection(result): | |
| 85 | -# geojsonresult = [togeojson(x) for x in result] | |
| 86 | -# data = {} | |
| 87 | -# data["type"] = "FeatureCollection" | |
| 88 | -# data["features"] = geojsonresult | |
| 89 | -# return data | |
| 90 | -# | |
| 91 | -# | |
| 92 | -# def getType(layer): | |
| 93 | -# origin = layer.GetGeomType() # type:str | |
| 94 | -# if origin == 1 or origin == 4: | |
| 95 | -# return "point" | |
| 96 | -# elif origin == 2 or origin == 5: | |
| 97 | -# return "linestring" | |
| 98 | -# elif origin == 3 or origin == 6: | |
| 99 | -# return "polygon" | |
| 100 | -# return str(origin) | |
| 101 | -# | |
| 102 | -# | |
| 103 | -# def objects_to_jsonarray(object): | |
| 104 | -# result = [] | |
| 105 | -# for o in object: | |
| 106 | -# result.append(object_to_json(o)) | |
| 107 | -# return result | |
| 108 | -# | |
| 109 | -# | |
| 110 | -# def object_to_json(object): | |
| 111 | -# info = {} | |
| 112 | -# if object: | |
| 113 | -# info = object.__dict__ | |
| 114 | -# try: | |
| 115 | -# del info['_sa_instance_state'] | |
| 116 | -# except: | |
| 117 | -# pass | |
| 118 | -# for key in info: | |
| 119 | -# if isinstance(info[key], datetime.datetime): | |
| 120 | -# info[key] = info[key].strftime('%Y-%m-%d %H:%M:%S') | |
| 121 | -# if isinstance(info[key], datetime.time): | |
| 122 | -# info[key] = info[key].strftime('%H:%M:%S') | |
| 123 | -# return info | |
| 124 | -# | |
| 125 | -# | |
| 126 | -# def create_zip(path, filepaths: list): | |
| 127 | -# """ | |
| 128 | -# 创建ZIP文件 并写入文件 (支持大文件夹) | |
| 129 | -# :param path: 创建的ZIP文件路径 | |
| 130 | -# :param filepaths: | |
| 131 | -# :return: | |
| 132 | -# """ | |
| 133 | -# try: | |
| 134 | -# with zipfile.ZipFile(path, 'w', zipfile.ZIP_DEFLATED) as zip: | |
| 135 | -# for filepath in filepaths: | |
| 136 | -# if os.path.isdir(filepath): | |
| 137 | -# pre_len = len(os.path.dirname(filepath)) | |
| 138 | -# for parent, dirnames, filenames in os.walk(filepath): | |
| 139 | -# for filename in filenames: | |
| 140 | -# pathfile = os.path.join(parent, filename) | |
| 141 | -# if pathfile != path: # 避免将新创建的zip写入该zip文件 | |
| 142 | -# arcname = pathfile[pre_len:].strip(os.path.sep) # 相对路径 不进行则会生成目录树 | |
| 143 | -# zip.write(pathfile, arcname) | |
| 144 | -# elif os.path.isfile(filepath): | |
| 145 | -# zip.write(filepath, os.path.basename(filepath)) | |
| 146 | -# else: | |
| 147 | -# print("创建zip文件对象失败!原因:未识别到路径") | |
| 148 | -# return "创建zip文件对象失败!原因:未识别到路径" | |
| 149 | -# return True | |
| 150 | -# | |
| 151 | -# except Exception as e: | |
| 152 | -# print("创建zip文件对象失败!原因:%s" % str(e)) | |
| 153 | -# return "创建zip文件对象失败!原因:%s" % str(e) | |
| 154 | -# | |
| 155 | -# def unzip(store_file): | |
| 156 | -# #处理zip | |
| 157 | -# store_path = os.path.dirname(store_file) | |
| 158 | -# zip_file = zipfile.ZipFile(store_file, 'r') | |
| 159 | -# | |
| 160 | -# #是否要重命名文件夹 | |
| 161 | -# rename_path = False | |
| 162 | -# rename_path_origin=None | |
| 163 | -# rename_path_after =None | |
| 164 | -# for names in zip_file.namelist(): | |
| 165 | -# #zipfile解压中文文件会有编码问题,需要解压后重命名 | |
| 166 | -# try: | |
| 167 | -# name_t = names.encode('cp437').decode('gbk') | |
| 168 | -# except: | |
| 169 | -# name_t = names.encode('utf-8').decode('utf-8') | |
| 170 | -# | |
| 171 | -# zip_file.extract(names,store_path,) | |
| 172 | -# | |
| 173 | -# os.chdir(store_path) # 切换到目标目录 | |
| 174 | -# | |
| 175 | -# if names.__contains__("/"): | |
| 176 | -# pat = names.split("/") | |
| 177 | -# pat2 = name_t.split("/")[-1] | |
| 178 | -# pat[-1] = pat2 | |
| 179 | -# name_tt = "/".join(pat) | |
| 180 | -# os.rename(names, name_tt) | |
| 181 | -# if not names[-1].__eq__("/"): | |
| 182 | -# rename_path = True | |
| 183 | -# rename_path_origin = names.split("/")[:-1] | |
| 184 | -# rename_path_after = name_t.split("/")[:-1] | |
| 185 | -# else: | |
| 186 | -# | |
| 187 | -# os.rename(names, name_t) # 重命名文件 | |
| 188 | -# # 重命名文件夹 | |
| 189 | -# if rename_path: | |
| 190 | -# for i in range(len(rename_path_origin),0,-1): | |
| 191 | -# origin = "/".join(rename_path_origin[:i]) | |
| 192 | -# rename_path_origin[i-1] = rename_path_after[i-1] | |
| 193 | -# after = "/".join(rename_path_origin[:i]) | |
| 194 | -# os.rename(origin, after) | |
| 195 | -# | |
| 196 | -# os.chdir(os.path.dirname(store_path)) | |
| 197 | -# zip_file.close() | |
| 198 | -# | |
| 199 | -# | |
| 200 | -# | |
| 201 | -# file_for_open = None | |
| 202 | -# encoding = None | |
| 203 | -# for root, dirs, files in os.walk(store_path): | |
| 204 | -# for fn in files: | |
| 205 | -# if fn.endswith("shp"): | |
| 206 | -# file_for_open = os.path.join(root, fn) | |
| 207 | -# if fn.endswith("cpg"): | |
| 208 | -# with open(os.path.join(root, fn)) as fd: | |
| 209 | -# encoding = fd.readline().strip() | |
| 210 | -# if fn.endswith("gdb"): | |
| 211 | -# print(fn) | |
| 212 | -# file_for_open =root | |
| 213 | -# | |
| 214 | -# return file_for_open,encoding | |
| 215 | -# | |
| 216 | -# def open_pg_data_source(iswrite,uri=configure.SQLALCHEMY_DATABASE_URI): | |
| 217 | -# """ | |
| 218 | -# # 获取PostGIS数据源 | |
| 219 | -# :return: | |
| 220 | -# """ | |
| 221 | -# db_conn_tuple = get_info_from_sqlachemy_uri(uri) | |
| 222 | -# fn = "PG: user=%s password=%s host=%s port=%s dbname=%s " % db_conn_tuple | |
| 223 | -# driver = ogr.GetDriverByName("PostgreSQL") | |
| 224 | -# if driver is None: | |
| 225 | -# raise Exception("打开PostgreSQL驱动失败,可能是当前GDAL未支持PostgreSQL驱动!") | |
| 226 | -# ds = driver.Open(fn, iswrite) | |
| 227 | -# if ds is None: | |
| 228 | -# raise Exception("打开数据源失败!") | |
| 229 | -# return ds | |
| 230 | -# | |
| 231 | -# | |
| 232 | -# def is_chinese(string): | |
| 233 | -# """ | |
| 234 | -# 检查整个字符串是否包含中文 | |
| 235 | -# :param string: 需要检查的字符串 | |
| 236 | -# :return: bool | |
| 237 | -# """ | |
| 238 | -# for ch in string: | |
| 239 | -# if u'\u4e00' <= ch <= u'\u9fff': | |
| 240 | -# return True | |
| 241 | -# | |
| 242 | -# return False | |
| 243 | -# | |
| 244 | -# | |
| 245 | -# def get_db_session(db_url=configure.SQLALCHEMY_DATABASE_URI,autocommit=False) -> session: | |
| 246 | -# engine = create_engine(db_url) | |
| 247 | -# system_session = sessionmaker(bind=engine,autocommit=autocommit)() | |
| 248 | -# return system_session | |
| 249 | -# | |
| 250 | -# | |
| 251 | -# class Queue: | |
| 252 | -# def __init__(self): | |
| 253 | -# self.items = [] | |
| 254 | -# def init(self,items): | |
| 255 | -# self.items = items | |
| 256 | -# def empty(self): | |
| 257 | -# return self.items == [] | |
| 258 | -# def append(self, item): | |
| 259 | -# self.items.insert(0,item) | |
| 260 | -# def pop(self): | |
| 261 | -# return self.items.pop() | |
| 262 | -# def size(self): | |
| 263 | -# return len(self.items) | |
| 264 | -# def __str__(self): | |
| 265 | -# return self.items.__str__() | |
| 266 | -# | |
| 267 | -# def structured_print(mes,type="info"): | |
| 268 | -# message = "[{}] {} {}".format(type.upper(),datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), mes) | |
| 269 | -# print(message) | |
| 270 | -# | |
| 271 | -# | |
| 272 | -# | |
| 273 | -# if __name__ == '__main__': | |
| 274 | -# print(get_info_from_sqlachemy_uri("postgresql://postgres:CDchinadci@2020@10.48.0.50:5432/dcidms")) | ... | ... |
| ... | ... | @@ -499,6 +499,12 @@ class VacuateProcess: |
| 499 | 499 | options = options[1:] |
| 500 | 500 | options.append("OVERWRITE=yes") |
| 501 | 501 | options.append("LAUNDER=no") |
| 502 | + | |
| 503 | + schema = layer.schema | |
| 504 | + # 增加统计字段 | |
| 505 | + schema.append(ogr.FieldDefn("_dcigrid_count_", ogr.OFTInteger)) | |
| 506 | + schema.append(ogr.FieldDefn("_dcigrid_name_", ogr.OFTString)) | |
| 507 | + | |
| 502 | 508 | for l in range(self.max_level): |
| 503 | 509 | this_grid_len = self.this_gridsize[l] |
| 504 | 510 | |
| ... | ... | @@ -523,14 +529,14 @@ class VacuateProcess: |
| 523 | 529 | v_ln = "z{}_vacuate_{}_{}".format(table_guid, self.t_grid_size.index(this_grid_len), grid_name) |
| 524 | 530 | vl = pg.CreateLayer(v_ln, layer.GetSpatialRef(),ogr.wkbUnknown, options) |
| 525 | 531 | # 抽稀表需要属性 |
| 526 | - vl.CreateFields(layer.schema) | |
| 532 | + vl.CreateFields(schema) | |
| 527 | 533 | self.vacuate_layers[l] = vl |
| 528 | 534 | |
| 529 | 535 | else: |
| 530 | 536 | pass |
| 531 | 537 | |
| 532 | 538 | |
| 533 | - def vacuate(self,g): | |
| 539 | + def vacuate(self,g,feature): | |
| 534 | 540 | |
| 535 | 541 | if self.is_spatial: |
| 536 | 542 | |
| ... | ... | @@ -567,6 +573,13 @@ class VacuateProcess: |
| 567 | 573 | feat.SetGeometry(center) |
| 568 | 574 | else: |
| 569 | 575 | feat.SetGeometry(g) |
| 576 | + | |
| 577 | + # 复制旧feature属性 | |
| 578 | + field_dict = feature.items() | |
| 579 | + for field_name in field_dict: | |
| 580 | + feat.SetField(field_name, field_dict[field_name]) | |
| 581 | + feat.SetField("_dcigrid_name_",".".join(key.split(".")[1:])) | |
| 582 | + | |
| 570 | 583 | vacuate_layer.CreateFeature(feat) |
| 571 | 584 | self.fill_dict[key] += 1 |
| 572 | 585 | #超大的还有机会 |
| ... | ... | @@ -574,8 +587,27 @@ class VacuateProcess: |
| 574 | 587 | vacuate_layer: Layer = self.vacuate_layers.get(level) |
| 575 | 588 | feat = ogr.Feature(vacuate_layer.GetLayerDefn()) |
| 576 | 589 | feat.SetGeometry(g) |
| 590 | + | |
| 591 | + # 复制旧feature属性 | |
| 592 | + field_dict = feature.items() | |
| 593 | + for field_name in field_dict: | |
| 594 | + feat.SetField(field_name, field_dict[field_name]) | |
| 595 | + feat.SetField("_dcigrid_name_",".".join(key.split(".")[1:])) | |
| 596 | + | |
| 577 | 597 | vacuate_layer.CreateFeature(feat) |
| 578 | 598 | self.fill_dict[key] += 1 |
| 599 | + else: | |
| 600 | + self.fill_dict[key] += 1 | |
| 601 | + | |
| 602 | + def set_vacuate_count(self): | |
| 603 | + if self.is_spatial: | |
| 604 | + # 插入到所有抽稀图层中 | |
| 605 | + for level in range(self.max_level): | |
| 606 | + vacuate_layer: Layer = self.vacuate_layers.get(level) | |
| 607 | + for feat in vacuate_layer: | |
| 608 | + key = "{}.{}".format(level,feat.GetField("_dcigrid_name_")) | |
| 609 | + feat.SetField("_dcigrid_count_",self.fill_dict.get(key)) | |
| 610 | + vacuate_layer.SetFeature(feat) | |
| 579 | 611 | |
| 580 | 612 | def end(self): |
| 581 | 613 | for pg in self.pg_ds_dict.values(): | ... | ... |
| ... | ... | @@ -12,6 +12,7 @@ import math |
| 12 | 12 | class SliceScheme: |
| 13 | 13 | |
| 14 | 14 | parameter={} |
| 15 | + levels = [] | |
| 15 | 16 | def __init__(self,slice_scheme_path): |
| 16 | 17 | tree = ET.parse(slice_scheme_path) |
| 17 | 18 | root:Element = tree.getroot() |
| ... | ... | @@ -27,6 +28,8 @@ class SliceScheme: |
| 27 | 28 | self.parameter["y"] = float(TileCacheInfo.find("TileOrigin").find("Y").text) |
| 28 | 29 | self.parameter["dpi"] = float(TileCacheInfo.find("DPI").text) |
| 29 | 30 | |
| 31 | + self.parameter["wkt"] = TileCacheInfo.find("SpatialReference").find("WKT").text | |
| 32 | + | |
| 30 | 33 | |
| 31 | 34 | LODInfos:Element = TileCacheInfo.find("LODInfos") |
| 32 | 35 | |
| ... | ... | @@ -37,6 +40,10 @@ class SliceScheme: |
| 37 | 40 | info_dict["resolution"] = float(info.find("Resolution").text) |
| 38 | 41 | self.parameter[info.find("LevelID").text] =info_dict |
| 39 | 42 | |
| 43 | + self.levels.append({"level":int(info.find("LevelID").text), | |
| 44 | + "scale":float(info.find("Scale").text), | |
| 45 | + "resolution":float(info.find("Resolution").text)}) | |
| 46 | + | |
| 40 | 47 | @staticmethod |
| 41 | 48 | def get_polygon(parameter,level,row,col): |
| 42 | 49 | level=int(level) |
| ... | ... | @@ -54,7 +61,7 @@ class SliceScheme: |
| 54 | 61 | |
| 55 | 62 | |
| 56 | 63 | |
| 57 | - def get_polygon2(self,level,row,col): | |
| 64 | + def get_poly(self,level,row,col): | |
| 58 | 65 | level=int(level) |
| 59 | 66 | row = int(row) |
| 60 | 67 | col = int(col) | ... | ... |
| ... | ... | @@ -3,20 +3,41 @@ |
| 3 | 3 | #createtime: 2021/7/15 |
| 4 | 4 | #email: nheweijun@sina.com |
| 5 | 5 | |
| 6 | -from pyDes import des,ECB,PAD_PKCS5 | |
| 7 | -import base64 | |
| 8 | -import numpy | |
| 9 | -import gzip | |
| 10 | -import sys | |
| 11 | -import json | |
| 12 | -# pixel_array = numpy.empty((256,256,3),dtype=int)+3 | |
| 13 | -# | |
| 14 | -# | |
| 15 | -# | |
| 16 | -# # 使用gzip 压缩传输 | |
| 17 | -# content = gzip.compress(pixel_array, 2) | |
| 18 | -# | |
| 19 | -# print(sys.getsizeof(json.dumps(pixel_array.tolist()))) | |
| 20 | -# print(sys.getsizeof((content))) | |
| 21 | -import random | |
| 22 | -print(int(random.random()*2)) | |
| \ No newline at end of file | ||
| 6 | +from osgeo import gdal | |
| 7 | + | |
| 8 | + | |
| 9 | +from osgeo import gdal, gdalconst | |
| 10 | +from osgeo import ogr | |
| 11 | + | |
| 12 | +rasterFile = 'F:/**0416.dat' # 原影像 | |
| 13 | +shpFile = 'F:/**小麦.shp' # 裁剪矩形 | |
| 14 | + | |
| 15 | +dataset = gdal.Open(rasterFile, gdalconst.GA_ReadOnly) | |
| 16 | + | |
| 17 | +geo_transform = dataset.GetGeoTransform() | |
| 18 | +cols = dataset.RasterXSize # 列数 | |
| 19 | +rows = dataset.RasterYSize # 行数 | |
| 20 | + | |
| 21 | +x_min = geo_transform[0] | |
| 22 | +y_min = geo_transform[3] | |
| 23 | +pixel_width = geo_transform[1] | |
| 24 | + | |
| 25 | +shp = ogr.Open(shpFile, 0) | |
| 26 | +m_layer = shp.GetLayerByIndex(0) | |
| 27 | + | |
| 28 | +target_ds = gdal.GetDriverByName('MEM').Create("", xsize=cols, ysize=rows, bands=1, | |
| 29 | + eType=gdal.GDT_Byte) | |
| 30 | +target_ds.SetGeoTransform(geo_transform) | |
| 31 | +target_ds.SetProjection(dataset.GetProjection()) | |
| 32 | + | |
| 33 | +band = target_ds.GetRasterBand(1) | |
| 34 | +band.SetNoDataValue(0) | |
| 35 | +band.FlushCache() | |
| 36 | +gdal.RasterizeLayer(target_ds, [1], m_layer) # 跟shp字段给栅格像元赋值 | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | +# gdal.RasterizeLayer(target_ds, [1], m_layer) # 多边形内像元值的全是255 | |
| 41 | +del dataset | |
| 42 | +del target_ds | |
| 43 | +shp.Release() | ... | ... |
请
注册
或
登录
后发表评论