正在显示
15 个修改的文件
包含
680 行增加
和
188 行删除
BuildImage-arm64/Dockerfile
0 → 100644
| 1 | +From osgeo/gdal:ubuntu-small-3.4.1 | |
| 2 | + | |
| 3 | + | |
| 4 | +WORKDIR /root | |
| 5 | +#设置编码 | |
| 6 | +ENV LANG=en_US.UTF-8 | |
| 7 | +#设置时区 | |
| 8 | +ENV TZ=Asia/Shanghai | |
| 9 | + | |
| 10 | +COPY . . | |
| 11 | + | |
| 12 | +RUN apt-get update | |
| 13 | +#安装pip3 | |
| 14 | +RUN apt-get install python3-pip -y | |
| 15 | +#安装apache2 | |
| 16 | +RUN apt-get install apache2 -y && apt-get install apache2-dev -y | |
| 17 | +#安装pg_config | |
| 18 | +RUN apt-get install libpq-dev | |
| 19 | +#安装依赖 | |
| 20 | +RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn | |
| 21 | + | |
| 22 | +RUN mod_wsgi-express install-module | |
| 23 | + | ... | ... |
BuildImage-arm64/requirements.txt
0 → 100644
| 1 | +flask==1.1.2 | |
| 2 | +SQLAlchemy==1.3.17 | |
| 3 | +Flask-SQLAlchemy==2.4.3 | |
| 4 | +flask_cors==3.0.8 | |
| 5 | +flasgger==0.9.5 | |
| 6 | +psycopg2-binary==2.8.5 | |
| 7 | +pyDes==2.0.1 | |
| 8 | +mod_wsgi==4.8.0 | |
| 9 | +opencv-python-headless==4.5.1.48 | |
| 10 | +thrift==0.13.0 | |
| 11 | +Authlib==0.13 | |
| 12 | +kazoo==2.8.0 | |
| 13 | +paramiko==2.8.0 | |
| 14 | +requests==2.26.0 | |
| 15 | +schedule==1.1.0 | |
| 16 | +gmssl==3.2.1 | |
| 17 | +pycryptodome==3.13.0 | |
| 18 | +oauthlib==3.2.0 | |
| 19 | + | |
| 20 | + | |
| 21 | +MarkupSafe==2.0.1 | |
| 22 | +itsdangerous==1.1.0 | |
| 23 | +Werkzeug==2.0.1 | |
| 24 | +Jinja2==3.0.1 | |
| \ No newline at end of file | ... | ... |
BuildImage-arm64/second-build/Dockerfile
0 → 100644
| 1 | +From osgeo/gdal:ubuntu-small-3.4.1 | |
| 2 | +WORKDIR /root | |
| 3 | +#设置编码 | |
| 4 | +ENV LANG=en_US.UTF-8 | |
| 5 | +#设置时区 | |
| 6 | +ENV TZ=Asia/Shanghai | |
| 7 | + | |
| 8 | +#安装apache2 | |
| 9 | +RUN apt-get update | |
| 10 | +RUN apt-get install apache2 -y | |
| 11 | + | |
| 12 | +COPY --from=dci/dmapserver:build-dev /usr/local /usr/local | |
| 13 | +COPY --from=dci/dmapserver:build-dev /usr/lib/apache2/modules /usr/lib/apache2/modules | |
| 14 | +CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"] | |
| 15 | + | |
| 16 | + | ... | ... |
| ... | ... | @@ -14,6 +14,8 @@ RUN apt-get update |
| 14 | 14 | RUN apt-get install python3-pip -y |
| 15 | 15 | #安装apache2 |
| 16 | 16 | RUN apt-get install apache2 -y && apt-get install apache2-dev -y |
| 17 | +#安装pg_config | |
| 18 | +RUN apt-get install libpq-dev | |
| 17 | 19 | #安装依赖 |
| 18 | 20 | RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn |
| 19 | 21 | ... | ... |
apache2.arm64.conf
0 → 100644
| 1 | +# This is the main Apache server configuration file. It contains the | |
| 2 | +# configuration directives that give the server its instructions. | |
| 3 | +# See http://httpd.apache.org/docs/2.4/ for detailed information about | |
| 4 | +# the directives and /usr/share/doc/apache2/README.Debian about Debian specific | |
| 5 | +# hints. | |
| 6 | +# | |
| 7 | +# | |
| 8 | +# Summary of how the Apache 2 configuration works in Debian: | |
| 9 | +# The Apache 2 web server configuration in Debian is quite different to | |
| 10 | +# upstream's suggested way to configure the web server. This is because Debian's | |
| 11 | +# default Apache2 installation attempts to make adding and removing modules, | |
| 12 | +# virtual hosts, and extra configuration directives as flexible as possible, in | |
| 13 | +# order to make automating the changes and administering the server as easy as | |
| 14 | +# possible. | |
| 15 | + | |
| 16 | +# It is split into several files forming the configuration hierarchy outlined | |
| 17 | +# below, all located in the /etc/apache2/ directory: | |
| 18 | +# | |
| 19 | +# /etc/apache2/ | |
| 20 | +# |-- apache2.conf | |
| 21 | +# | `-- ports.conf | |
| 22 | +# |-- mods-enabled | |
| 23 | +# | |-- *.load | |
| 24 | +# | `-- *.conf | |
| 25 | +# |-- conf-enabled | |
| 26 | +# | `-- *.conf | |
| 27 | +# `-- sites-enabled | |
| 28 | +# `-- *.conf | |
| 29 | +# | |
| 30 | +# | |
| 31 | +# * apache2.conf is the main configuration file (this file). It puts the pieces | |
| 32 | +# together by including all remaining configuration files when starting up the | |
| 33 | +# web server. | |
| 34 | +# | |
| 35 | +# * ports.conf is always included from the main configuration file. It is | |
| 36 | +# supposed to determine listening ports for incoming connections which can be | |
| 37 | +# customized anytime. | |
| 38 | +# | |
| 39 | +# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ | |
| 40 | +# directories contain particular configuration snippets which manage modules, | |
| 41 | +# global configuration fragments, or virtual host configurations, | |
| 42 | +# respectively. | |
| 43 | +# | |
| 44 | +# They are activated by symlinking available configuration files from their | |
| 45 | +# respective *-available/ counterparts. These should be managed by using our | |
| 46 | +# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See | |
| 47 | +# their respective man pages for detailed information. | |
| 48 | +# | |
| 49 | +# * The binary is called apache2. Due to the use of environment variables, in | |
| 50 | +# the default configuration, apache2 needs to be started/stopped with | |
| 51 | +# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not | |
| 52 | +# work with the default configuration. | |
| 53 | + | |
| 54 | + | |
| 55 | +# Global configuration | |
| 56 | +# | |
| 57 | + | |
| 58 | +# | |
| 59 | +# ServerRoot: The top of the directory tree under which the server's | |
| 60 | +# configuration, error, and log files are kept. | |
| 61 | +# | |
| 62 | +# NOTE! If you intend to place this on an NFS (or otherwise network) | |
| 63 | +# mounted filesystem then please read the Mutex documentation (available | |
| 64 | +# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>); | |
| 65 | +# you will save yourself a lot of trouble. | |
| 66 | +# | |
| 67 | +# Do NOT add a slash at the end of the directory path. | |
| 68 | +# | |
| 69 | +#ServerRoot "/etc/apache2" | |
| 70 | + | |
| 71 | +# | |
| 72 | +# The accept serialization lock file MUST BE STORED ON A LOCAL DISK. | |
| 73 | +# | |
| 74 | +#Mutex file:${APACHE_LOCK_DIR} default | |
| 75 | + | |
| 76 | +# | |
| 77 | +# The directory where shm and other runtime files will be stored. | |
| 78 | +# | |
| 79 | + | |
| 80 | +DefaultRuntimeDir ${APACHE_RUN_DIR} | |
| 81 | + | |
| 82 | +# | |
| 83 | +# PidFile: The file in which the server should record its process | |
| 84 | +# identification number when it starts. | |
| 85 | +# This needs to be set in /etc/apache2/envvars | |
| 86 | +# | |
| 87 | +PidFile ${APACHE_PID_FILE} | |
| 88 | + | |
| 89 | +# | |
| 90 | +# Timeout: The number of seconds before receives and sends time out. | |
| 91 | +# | |
| 92 | +Timeout 300 | |
| 93 | + | |
| 94 | +# | |
| 95 | +# KeepAlive: Whether or not to allow persistent connections (more than | |
| 96 | +# one request per connection). Set to "Off" to deactivate. | |
| 97 | +# | |
| 98 | +KeepAlive On | |
| 99 | + | |
| 100 | +# | |
| 101 | +# MaxKeepAliveRequests: The maximum number of requests to allow | |
| 102 | +# during a persistent connection. Set to 0 to allow an unlimited amount. | |
| 103 | +# We recommend you leave this number high, for maximum performance. | |
| 104 | +# | |
| 105 | +MaxKeepAliveRequests 100 | |
| 106 | + | |
| 107 | +# | |
| 108 | +# KeepAliveTimeout: Number of seconds to wait for the next request from the | |
| 109 | +# same client on the same connection. | |
| 110 | +# | |
| 111 | +KeepAliveTimeout 5 | |
| 112 | + | |
| 113 | + | |
| 114 | +# These need to be set in /etc/apache2/envvars | |
| 115 | +User ${APACHE_RUN_USER} | |
| 116 | +Group ${APACHE_RUN_GROUP} | |
| 117 | + | |
| 118 | +# | |
| 119 | +# HostnameLookups: Log the names of clients or just their IP addresses | |
| 120 | +# e.g., www.apache.org (on) or 204.62.129.132 (off). | |
| 121 | +# The default is off because it'd be overall better for the net if people | |
| 122 | +# had to knowingly turn this feature on, since enabling it means that | |
| 123 | +# each client request will result in AT LEAST one lookup request to the | |
| 124 | +# nameserver. | |
| 125 | +# | |
| 126 | +HostnameLookups Off | |
| 127 | + | |
| 128 | +# ErrorLog: The location of the error log file. | |
| 129 | +# If you do not specify an ErrorLog directive within a <VirtualHost> | |
| 130 | +# container, error messages relating to that virtual host will be | |
| 131 | +# logged here. If you *do* define an error logfile for a <VirtualHost> | |
| 132 | +# container, that host's errors will be logged there and not here. | |
| 133 | +# | |
| 134 | +ErrorLog ${APACHE_LOG_DIR}/error.log | |
| 135 | + | |
| 136 | +# | |
| 137 | +# LogLevel: Control the severity of messages logged to the error_log. | |
| 138 | +# Available values: trace8, ..., trace1, debug, info, notice, warn, | |
| 139 | +# error, crit, alert, emerg. | |
| 140 | +# It is also possible to configure the log level for particular modules, e.g. | |
| 141 | +# "LogLevel info ssl:warn" | |
| 142 | +# | |
| 143 | +LogLevel warn | |
| 144 | + | |
| 145 | +# Include module configuration: | |
| 146 | +IncludeOptional mods-enabled/*.load | |
| 147 | +IncludeOptional mods-enabled/*.conf | |
| 148 | + | |
| 149 | +# Include list of ports to listen on | |
| 150 | +Include ports.conf | |
| 151 | + | |
| 152 | + | |
| 153 | +# Sets the default security model of the Apache2 HTTPD server. It does | |
| 154 | +# not allow access to the root filesystem outside of /usr/share and /var/www. | |
| 155 | +# The former is used by web applications packaged in Debian, | |
| 156 | +# the latter may be used for local directories served by the web server. If | |
| 157 | +# your system is serving content from a sub-directory in /srv you must allow | |
| 158 | +# access here, or in any related virtual host. | |
| 159 | +<Directory /> | |
| 160 | + Options FollowSymLinks | |
| 161 | + AllowOverride None | |
| 162 | + Require all denied | |
| 163 | +</Directory> | |
| 164 | + | |
| 165 | +<Directory /usr/share> | |
| 166 | + AllowOverride None | |
| 167 | + Require all granted | |
| 168 | +</Directory> | |
| 169 | + | |
| 170 | +<Directory /var/www/> | |
| 171 | + Options Indexes FollowSymLinks | |
| 172 | + AllowOverride All | |
| 173 | + Require all granted | |
| 174 | +</Directory> | |
| 175 | + | |
| 176 | +#<Directory /srv/> | |
| 177 | +# Options Indexes FollowSymLinks | |
| 178 | +# AllowOverride None | |
| 179 | +# Require all granted | |
| 180 | +#</Directory> | |
| 181 | + | |
| 182 | + | |
| 183 | +# AccessFileName: The name of the file to look for in each directory | |
| 184 | +# for additional configuration directives. See also the AllowOverride | |
| 185 | +# directive. | |
| 186 | +# | |
| 187 | +AccessFileName .htaccess | |
| 188 | + | |
| 189 | +# | |
| 190 | +# The following lines prevent .htaccess and .htpasswd files from being | |
| 191 | +# viewed by Web clients. | |
| 192 | +# | |
| 193 | +<FilesMatch "^\.ht"> | |
| 194 | + Require all denied | |
| 195 | +</FilesMatch> | |
| 196 | + | |
| 197 | + | |
| 198 | +# | |
| 199 | +# The following directives define some format nicknames for use with | |
| 200 | +# a CustomLog directive. | |
| 201 | +# | |
| 202 | +# These deviate from the Common Log Format definitions in that they use %O | |
| 203 | +# (the actual bytes sent including headers) instead of %b (the size of the | |
| 204 | +# requested file), because the latter makes it impossible to detect partial | |
| 205 | +# requests. | |
| 206 | +# | |
| 207 | +# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended. | |
| 208 | +# Use mod_remoteip instead. | |
| 209 | +# | |
| 210 | +LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined | |
| 211 | +LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined | |
| 212 | +LogFormat "%h %l %u %t \"%r\" %>s %O" common | |
| 213 | +LogFormat "%{Referer}i -> %U" referer | |
| 214 | +LogFormat "%{User-agent}i" agent | |
| 215 | + | |
| 216 | +# Include of directories ignores editors' and dpkg's backup files, | |
| 217 | +# see README.Debian for details. | |
| 218 | + | |
| 219 | +# Include generic snippets of statements | |
| 220 | +IncludeOptional conf-enabled/*.conf | |
| 221 | + | |
| 222 | +# Include the virtual host configurations: | |
| 223 | +IncludeOptional sites-enabled/*.conf | |
| 224 | + | |
| 225 | +LoadModule wsgi_module "/usr/lib/apache2/modules/mod_wsgi-py38.cpython-38-aarch64-linux-gnu.so" | |
| 226 | +WSGIPythonHome "/usr" | |
| 227 | + | |
| 228 | +LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so | |
| \ No newline at end of file | ... | ... |
compile-py38.py
0 → 100644
| 1 | +# coding=utf-8 | |
| 2 | +#author: 4N | |
| 3 | +#createtime: 2022/2/28 | |
| 4 | +#email: nheweijun@sina.com | |
| 5 | + | |
| 6 | +import py_compile | |
| 7 | +import os | |
| 8 | +import shutil | |
| 9 | + | |
| 10 | +def compile(des): | |
| 11 | + | |
| 12 | + | |
| 13 | + project_dir = os.path.dirname(os.path.realpath(__file__)) | |
| 14 | + if os.path.normpath(project_dir) == os.path.normpath(des): | |
| 15 | + raise Exception("目标目录不能与代码目录一样!") | |
| 16 | + | |
| 17 | + if os.path.exists(des): | |
| 18 | + os.system("rd/s/q {}".format(des)) | |
| 19 | + shutil.rmtree(des, True) | |
| 20 | + | |
| 21 | + shutil.copytree(project_dir, des) | |
| 22 | + git_path = os.path.join(des,".git") | |
| 23 | + if os.path.exists(os.path.join(des,".git")): | |
| 24 | + os.system("rd/s/q {}".format(git_path)) | |
| 25 | + | |
| 26 | + for root, dirs, files in os.walk(os.path.join(des,"app")): | |
| 27 | + for fn in files: | |
| 28 | + if fn.endswith("py"): | |
| 29 | + py_file = os.path.join(root, fn) | |
| 30 | + py_compile.compile(py_file) | |
| 31 | + os.remove(py_file) | |
| 32 | + pyc_file = os.path.join(root, "__pycache__",fn.split(".")[0]+".cpython-38.pyc") | |
| 33 | + des_pyc_file = os.path.join(root,fn.split(".")[0]+".pyc") | |
| 34 | + shutil.copy(pyc_file,des_pyc_file) | |
| 35 | + | |
| 36 | +if __name__ == '__main__': | |
| 37 | + des="H:\DMapManager" | |
| 38 | + compile(des) | |
| 39 | + | ... | ... |
| ... | ... | @@ -37,9 +37,9 @@ echo "正在启动容器..." |
| 37 | 37 | |
| 38 | 38 | set="--restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port1:80 -p $port2:81 " |
| 39 | 39 | codeMap="-v ${curPath}:/usr/src/app -v ${curPath}/html:/var/www/html" |
| 40 | -apacheMap="-v ${curPath}/apache2.conf:/etc/apache2/apache2.conf -v ${curPath}/dmapmanager.conf:/etc/apache2/sites-enabled/dmapmanager.conf -v ${curPath}/envvars:/etc/apache2/envvars" | |
| 40 | +apacheMap="-v ${curPath}/apache2.arm64.conf:/etc/apache2/apache2.conf -v ${curPath}/dmapmanager.conf:/etc/apache2/sites-enabled/dmapmanager.conf -v ${curPath}/envvars:/etc/apache2/envvars" | |
| 41 | 41 | |
| 42 | -docker run -it -d --name ${container_name} ${set} ${codeMap} ${apacheMap} dci/dmapmanager:4.1 | |
| 42 | +docker run -it -d --name ${container_name} ${set} ${codeMap} ${apacheMap} dci/dmapmanager:4.0-arm64 | |
| 43 | 43 | sleep 5 |
| 44 | 44 | curl localhost:$port2/release |
| 45 | 45 | ... | ... |
run.apache.ubuntu.x86.sh
0 → 100644
| 1 | +#! /bin/sh | |
| 2 | +container_name="dmapmanager" | |
| 3 | +#停止容器 | |
| 4 | +echo "正在关闭容器..." | |
| 5 | +docker stop $container_name | |
| 6 | +docker rm $container_name | |
| 7 | + | |
| 8 | +curPath=$(readlink -f $(dirname $0)) | |
| 9 | + | |
| 10 | + | |
| 11 | +#设置日志权限 | |
| 12 | +chmod -R 777 $curPath | |
| 13 | + | |
| 14 | +#设置端口 | |
| 15 | +port="" | |
| 16 | +if [ ! -n "$1" ] ;then | |
| 17 | + | |
| 18 | +port1="8830" | |
| 19 | +echo "未设置端口1,使用默认8830端口..." | |
| 20 | +else | |
| 21 | +port1=$1 | |
| 22 | +echo "端口1设置为$1 ..." | |
| 23 | +fi | |
| 24 | + | |
| 25 | +port2="" | |
| 26 | +if [ ! -n "$2" ] ;then | |
| 27 | +port2="8840" | |
| 28 | +echo "未设置端口2,使用默认8840端口..." | |
| 29 | +else | |
| 30 | +port2=$2 | |
| 31 | +echo "端口2设置为$2 ..." | |
| 32 | +fi | |
| 33 | + | |
| 34 | + | |
| 35 | +#启动容器 | |
| 36 | +echo "正在启动容器..." | |
| 37 | + | |
| 38 | +set="--restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port1:80 -p $port2:81 " | |
| 39 | +codeMap="-v ${curPath}:/usr/src/app -v ${curPath}/html:/var/www/html" | |
| 40 | +apacheMap="-v ${curPath}/apache2.x86.conf:/etc/apache2/apache2.conf -v ${curPath}/dmapmanager.conf:/etc/apache2/sites-enabled/dmapmanager.conf -v ${curPath}/envvars:/etc/apache2/envvars" | |
| 41 | + | |
| 42 | +docker run -it -d --name ${container_name} ${set} ${codeMap} ${apacheMap} dci/dmapmanager:4.0-x86 | |
| 43 | +sleep 5 | |
| 44 | +curl localhost:$port2/release | |
| 45 | + | ... | ... |
| ... | ... | @@ -16,7 +16,7 @@ else |
| 16 | 16 | echo "端口设置为$1 ..." |
| 17 | 17 | fi |
| 18 | 18 | |
| 19 | -docker run -d --name $dn -e TZ="Asia/Shanghai" --restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port:8840 -v $curPath:/usr/src/app -w /usr/src/app dci/dmapmanager:4.1 python3 ./run.py | |
| 19 | +docker run -d --name $dn -e TZ="Asia/Shanghai" --restart=always -e ALLOW_IP_RANGE=0.0.0.0/0 -p $port:8840 -v $curPath:/usr/src/app -w /usr/src/app dci/dmapmanager:4.0 python3 ./run.py | |
| 20 | 20 | # 清除未完成的任务任务 |
| 21 | 21 | sleep 5 |
| 22 | 22 | curl localhost:$port/release |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -28,7 +28,7 @@ class MapSynthesize: |
| 28 | 28 | data:ShapeData |
| 29 | 29 | area_threshold = 10.0 |
| 30 | 30 | buffer_threshold = 100.0 |
| 31 | - distance_buffer_threshold = 1.114691025217302e-04 | |
| 31 | + | |
| 32 | 32 | |
| 33 | 33 | def __init__(self,data): |
| 34 | 34 | self.data = data |
| ... | ... | @@ -46,7 +46,7 @@ class MapSynthesize: |
| 46 | 46 | short_length = min(polygon_env[1]-polygon_env[0],polygon_env[3]-polygon_env[2]) |
| 47 | 47 | |
| 48 | 48 | center:Geometry = polygon.Centroid() |
| 49 | - # print(center) | |
| 49 | + | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | # 提前return |
| ... | ... | @@ -87,6 +87,9 @@ class MapSynthesize: |
| 87 | 87 | oneside_area, otherside_area = None,None |
| 88 | 88 | for angle in direction: |
| 89 | 89 | |
| 90 | + # print("\"" + center.ExportToWkt() + "\",") | |
| 91 | + | |
| 92 | + | |
| 90 | 93 | if in_hole: |
| 91 | 94 | line = self.get_doubleline(center.GetX(),center.GetY(),angle,line_length) |
| 92 | 95 | else: |
| ... | ... | @@ -181,7 +184,7 @@ class MapSynthesize: |
| 181 | 184 | plist_d.sort(key=lambda x:x[1]) |
| 182 | 185 | reprecent_point = self.creat_point(((plist_d[0][0].GetX()+ plist_d[1][0].GetX())/2.0, (plist_d[0][0].GetY()+plist_d[1][0].GetY())/2.0)) |
| 183 | 186 | |
| 184 | - # print("\""+reprecent_point.ExportToWkt() + "\",") | |
| 187 | + | |
| 185 | 188 | |
| 186 | 189 | rp = RepresentPoint(reprecent_point,polygon) |
| 187 | 190 | |
| ... | ... | @@ -216,24 +219,33 @@ class MapSynthesize: |
| 216 | 219 | return line |
| 217 | 220 | |
| 218 | 221 | def get_radline(self,x0,y0,x1,y1,len_size): |
| 222 | + | |
| 219 | 223 | a2 = math.pow((x1-x0),2) |
| 220 | 224 | b2 = math.pow((y1-y0),2) |
| 221 | 225 | len_size = len_size+ math.sqrt(a2+b2) |
| 222 | 226 | |
| 223 | 227 | line: Geometry = ogr.Geometry(ogr.wkbLineString) |
| 224 | 228 | line.AddPoint(x0, y0) |
| 225 | - tanx = abs(y1-y0) / abs(x1-x0) | |
| 226 | - cosx = 1 / math.sqrt(1 + tanx *tanx) | |
| 227 | - dx = cosx* len_size | |
| 228 | - dy = tanx * dx | |
| 229 | + | |
| 230 | + | |
| 229 | 231 | |
| 230 | 232 | if x1 == x0: |
| 231 | 233 | x2 = x0 |
| 234 | + # if y1 > y0 : | |
| 235 | + # y2 = y0 + abs(dy) | |
| 236 | + # else: | |
| 237 | + # y2 = y0 - abs(dy) | |
| 232 | 238 | if y1 > y0 : |
| 233 | - y2 = y0 + abs(dy) | |
| 239 | + y2 = y0 + abs(len_size) | |
| 234 | 240 | else: |
| 235 | - y2 = y0 - abs(dy) | |
| 241 | + y2 = y0 - abs(len_size) | |
| 236 | 242 | else: |
| 243 | + | |
| 244 | + tanx = abs(y1 - y0) / abs(x1 - x0) | |
| 245 | + cosx = 1 / math.sqrt(1 + tanx * tanx) | |
| 246 | + dx = cosx * len_size | |
| 247 | + dy = tanx * dx | |
| 248 | + | |
| 237 | 249 | if x1 < x0: |
| 238 | 250 | x2 = x0 - dx |
| 239 | 251 | else: |
| ... | ... | @@ -293,7 +305,6 @@ class MapSynthesize: |
| 293 | 305 | else: |
| 294 | 306 | triangle1, triangle2 = self.get_side_triangle(line, angle) |
| 295 | 307 | |
| 296 | - | |
| 297 | 308 | for gi in range(clip_geom.GetGeometryCount()): |
| 298 | 309 | clip_geom_i: Geometry = clip_geom.GetGeometryRef(gi) |
| 299 | 310 | it = clip_geom_i.Intersection(triangle1) |
| ... | ... | @@ -320,7 +331,6 @@ class MapSynthesize: |
| 320 | 331 | |
| 321 | 332 | mid_angle = (angle1 + angle2)/2.0 |
| 322 | 333 | |
| 323 | - | |
| 324 | 334 | if in_hole: |
| 325 | 335 | line = self.get_doubleline(center.GetX(), center.GetY(), mid_angle, line_length) |
| 326 | 336 | else: |
| ... | ... | @@ -577,69 +587,6 @@ class MapSynthesize: |
| 577 | 587 | |
| 578 | 588 | return polygon_line |
| 579 | 589 | |
| 580 | - def merge_concave(self, trees, distance_threshold): | |
| 581 | - merge_polygons = [] | |
| 582 | - count = 1 | |
| 583 | - | |
| 584 | - for tree in trees: | |
| 585 | - print(count) | |
| 586 | - count+=1 | |
| 587 | - polygons = list(tree.get_polygons()) | |
| 588 | - | |
| 589 | - merge_raw: Geometry = polygons[0] | |
| 590 | - for p in polygons: | |
| 591 | - merge_raw = merge_raw.Union(p) | |
| 592 | - | |
| 593 | - points = [] | |
| 594 | - | |
| 595 | - | |
| 596 | - for i in range(merge_raw.GetGeometryCount()): | |
| 597 | - | |
| 598 | - poly = merge_raw.GetGeometryRef(i) | |
| 599 | - poly_line :Geometry = self.get_polygon_lines(poly) | |
| 600 | - if poly_line: | |
| 601 | - for indx in range(poly_line.GetPointCount() - 1): | |
| 602 | - poi = poly_line.GetPoint(indx) | |
| 603 | - | |
| 604 | - points.append(poi) | |
| 605 | - | |
| 606 | - poi_next = poly_line.GetPoint(indx + 1) | |
| 607 | - | |
| 608 | - dis = math.sqrt(math.pow(poi[0] - poi_next[0], 2) + math.pow(poi[1] - poi_next[1], 2)) | |
| 609 | - # print(dis) | |
| 610 | - if dis > distance_threshold: | |
| 611 | - times = int(dis / distance_threshold) | |
| 612 | - # print(times) | |
| 613 | - for time in range(1, times + 1): | |
| 614 | - x, y = self.get_subpoint(poi[0], poi[1], poi_next[0], poi_next[1], (time * distance_threshold)) | |
| 615 | - points.append([x, y]) | |
| 616 | - | |
| 617 | - points = np.array([[p[0], p[1]] for p in points]) | |
| 618 | - | |
| 619 | - | |
| 620 | - cp = [] | |
| 621 | - for pp in points: | |
| 622 | - poi = ogr.Geometry(ogr.wkbPoint) | |
| 623 | - poi.AddPoint(pp[0], pp[1]) | |
| 624 | - cp.append(poi) | |
| 625 | - | |
| 626 | - merge_p_line = concaveHull(points, 3) | |
| 627 | - | |
| 628 | - ring = ogr.Geometry(ogr.wkbLinearRing) | |
| 629 | - | |
| 630 | - merge_p = ogr.Geometry(ogr.wkbPolygon) | |
| 631 | - | |
| 632 | - for l in merge_p_line: | |
| 633 | - ring.AddPoint(l[0], l[1]) | |
| 634 | - | |
| 635 | - ring.AddPoint(merge_p_line[0][0], merge_p_line[0][1]) | |
| 636 | - | |
| 637 | - merge_p.AddGeometry(ring) | |
| 638 | - merge_p = merge_p.Simplify(self.distance_buffer_threshold/10) | |
| 639 | - merge_polygons.append(merge_p) | |
| 640 | - | |
| 641 | - return merge_polygons | |
| 642 | - | |
| 643 | 590 | def get_subpoint(self, x0, y0, x1, y1, len_size): |
| 644 | 591 | |
| 645 | 592 | len_size = len_size |
| ... | ... | @@ -667,13 +614,19 @@ class MapSynthesize: |
| 667 | 614 | |
| 668 | 615 | return x2, y2 |
| 669 | 616 | |
| 670 | - def process(self): | |
| 617 | + def process(self,distance_buffer_threshold): | |
| 618 | + | |
| 619 | + # self.distance_buffer_threshold = distance_buffer_threshold | |
| 620 | + | |
| 671 | 621 | polygons = self.data.get_polygons() |
| 672 | 622 | rps = [] |
| 673 | 623 | |
| 674 | 624 | for poly in polygons: |
| 675 | 625 | rp = self.get_polygon_reprecent_point(poly) |
| 676 | 626 | rps.append(rp) |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 677 | 630 | print("完成代表点计算") |
| 678 | 631 | |
| 679 | 632 | #代表点要融合 |
| ... | ... | @@ -682,17 +635,26 @@ class MapSynthesize: |
| 682 | 635 | print("完成树生成计算") |
| 683 | 636 | min_delauney = self.create_min_delauney(delauney_lines,rps_sub) |
| 684 | 637 | print("完成最小生成树计算") |
| 685 | - trees = self.cut_delauney_min_tree(min_delauney,self.distance_buffer_threshold) | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + trees = self.cut_delauney_min_tree(min_delauney,distance_buffer_threshold) | |
| 686 | 642 | print("完成树裁剪") |
| 687 | 643 | |
| 644 | + | |
| 688 | 645 | polygon_result = [] |
| 646 | + print(len(list(trees))) | |
| 689 | 647 | for index,tree in enumerate(trees): |
| 690 | - | |
| 691 | - polygons = tree.get_polygons() | |
| 692 | 648 | print(index) |
| 649 | + polygons = tree.get_polygons() | |
| 650 | + # print(index) | |
| 693 | 651 | polygons = list(polygons) |
| 694 | - print(len(polygons)) | |
| 695 | - polygon_result.append(PolygonMerge.merge(polygons,self.distance_buffer_threshold)) | |
| 652 | + # print(len(polygons)) | |
| 653 | + | |
| 654 | + | |
| 655 | + polygon_result.append(PolygonMerge.merge(polygons,distance_buffer_threshold)) | |
| 656 | + | |
| 657 | + # polygon_result.extend(PolygonMerge.merge(polygons,self.distance_buffer_threshold)) | |
| 696 | 658 | |
| 697 | 659 | # polygons = self.merge_concave(trees,self.distance_buffer_threshold) |
| 698 | 660 | |
| ... | ... | @@ -703,11 +665,16 @@ if __name__ == '__main__': |
| 703 | 665 | |
| 704 | 666 | |
| 705 | 667 | t1 = time.time() |
| 706 | - sd = ShapeData(r"J:\Data\制图综合result\zhongshansub.shp") | |
| 668 | + sd = ShapeData(r"J:\Data\制图综合result\zhongshan_2_5w.shp") | |
| 707 | 669 | |
| 708 | 670 | mapsynthesize = MapSynthesize(sd) |
| 709 | - wkts = mapsynthesize.process() | |
| 710 | - result = r"J:\Data\制图综合result\zhongshansub_merge22.shp" | |
| 671 | + | |
| 672 | + base = 9.009009009009009009009009009009e-5 | |
| 673 | + | |
| 674 | + wkts = mapsynthesize.process(base*5) | |
| 675 | + | |
| 676 | + | |
| 677 | + result = r"J:\Data\制图综合result\zhongshan_5w.shp" | |
| 711 | 678 | ShapeData.create_shp_fromwkts(result,"zh",wkts) |
| 712 | 679 | |
| 713 | 680 | print(time.time()-t1) |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -6,10 +6,9 @@ |
| 6 | 6 | |
| 7 | 7 | from osgeo import ogr,gdal |
| 8 | 8 | from osgeo.ogr import * |
| 9 | - | |
| 10 | -from test.zonghe.ShapeData import ShapeData | |
| 9 | +from test.MapSynthesize.ShapeData import ShapeData | |
| 11 | 10 | import copy |
| 12 | - | |
| 11 | +import math | |
| 13 | 12 | from rtreelib import RTree,Rect |
| 14 | 13 | |
| 15 | 14 | |
| ... | ... | @@ -49,38 +48,69 @@ class PolygonMerge: |
| 49 | 48 | if d < 0: |
| 50 | 49 | polygon_line_points.reverse() |
| 51 | 50 | |
| 52 | - tris = list(cls.get_tri(polygon_line_points)) | |
| 51 | + tris = list(cls.simple_polygon_division(polygon_line_points)) | |
| 53 | 52 | |
| 54 | 53 | return tris |
| 55 | 54 | |
| 56 | 55 | @classmethod |
| 57 | - def get_tri(cls,polygon_line_points:list): | |
| 58 | - | |
| 59 | - if len(polygon_line_points) == 4 or len(polygon_line_points) == 3: | |
| 56 | + def simple_polygon_division(cls,polygon_line_points:list): | |
| 57 | + ''' | |
| 58 | + 简单多边形三角剖分算法 | |
| 59 | + :param polygon_line_points: 多边形逆时针点序列 | |
| 60 | + :return: | |
| 61 | + ''' | |
| 62 | + | |
| 63 | + if len(polygon_line_points) == 4: | |
| 60 | 64 | yield cls.create_polygon(polygon_line_points) |
| 61 | 65 | else: |
| 62 | 66 | for index,point in enumerate(polygon_line_points): |
| 63 | - if index == 0: | |
| 64 | - continue | |
| 65 | - else: | |
| 66 | - try: | |
| 67 | - point_front = polygon_line_points[index-1] | |
| 68 | - point_next = polygon_line_points[index+1] | |
| 69 | - except Exception as e: | |
| 70 | - print(e) | |
| 71 | - kk=1 | |
| 72 | - d=1 | |
| 73 | - | |
| 74 | - check = (point[0]-point_front[0]) * (point_next[1]-point[1]) - (point_next[0]-point[0])*(point[1]-point_front[1]) | |
| 75 | - | |
| 67 | + try: | |
| 68 | + if index == 0: | |
| 69 | + point_front = polygon_line_points[-1] | |
| 70 | + point_next = polygon_line_points[1] | |
| 71 | + elif index == len(polygon_line_points) - 1: | |
| 72 | + point_front = polygon_line_points[index - 1] | |
| 73 | + point_next = polygon_line_points[0] | |
| 74 | + else: | |
| 75 | + point_front = polygon_line_points[index - 1] | |
| 76 | + point_next = polygon_line_points[index + 1] | |
| 77 | + | |
| 78 | + except: | |
| 79 | + dd=1 | |
| 80 | + check = (point[0] - point_front[0]) * (point_next[1] -point[1]) - (point_next[0] - point[0]) * (point[1] - point_front[1]) | |
| 81 | + | |
| 82 | + #如果是凸点 | |
| 76 | 83 | if check > 0: |
| 77 | 84 | triangle = cls.create_polygon([point_front,point,point_next,point_front]) |
| 78 | - yield triangle | |
| 79 | 85 | |
| 80 | - polygon_line_points.pop(index) | |
| 81 | - for tri in cls.get_tri(polygon_line_points): | |
| 82 | - yield tri | |
| 83 | - break | |
| 86 | + #判断是否包含其他点 | |
| 87 | + contains = False | |
| 88 | + for i,poi_xy in enumerate(polygon_line_points): | |
| 89 | + | |
| 90 | + if index == 0: | |
| 91 | + if i in [0, 1, len(polygon_line_points) - 1]: | |
| 92 | + continue | |
| 93 | + | |
| 94 | + elif index == len(polygon_line_points) - 1: | |
| 95 | + if i in [index, 0 ,index - 1]: | |
| 96 | + continue | |
| 97 | + else: | |
| 98 | + if i in [index, index-1, index+1]: | |
| 99 | + continue | |
| 100 | + | |
| 101 | + poi:Geometry = ogr.Geometry(ogr.wkbPoint) | |
| 102 | + poi.AddPoint(poi_xy[0],poi_xy[1]) | |
| 103 | + if triangle.Contains(poi): | |
| 104 | + contains = True | |
| 105 | + | |
| 106 | + #如果不包含其他点,为有效剖分,结束循环 | |
| 107 | + if not contains: | |
| 108 | + yield triangle | |
| 109 | + polygon_line_points.pop(index) | |
| 110 | + for tri in cls.simple_polygon_division(polygon_line_points): | |
| 111 | + yield tri | |
| 112 | + break | |
| 113 | + | |
| 84 | 114 | |
| 85 | 115 | @classmethod |
| 86 | 116 | def merge(cls,polygons:list,distance_buffer_threshold): |
| ... | ... | @@ -92,30 +122,27 @@ class PolygonMerge: |
| 92 | 122 | # for poly in polygons: |
| 93 | 123 | # multipolygon.AddGeometry(poly) |
| 94 | 124 | |
| 125 | + tris = [] | |
| 95 | 126 | for poly in polygons: |
| 96 | 127 | polygon = polygon.Union(poly) |
| 97 | 128 | |
| 98 | - | |
| 99 | - | |
| 100 | 129 | delauney: Geometry = polygon.DelaunayTriangulation() |
| 101 | 130 | |
| 102 | 131 | for index in range(delauney.GetGeometryCount()): |
| 103 | 132 | de:Geometry = copy.deepcopy(delauney.GetGeometryRef(index)) |
| 104 | 133 | de_extent = de.GetEnvelope() |
| 105 | 134 | rtree.insert(RTreeData(de,1), env2rect(de_extent)) |
| 135 | + tris.append(de) | |
| 106 | 136 | |
| 107 | 137 | bians: list = cls.get_bian(polygon) |
| 108 | 138 | |
| 109 | - | |
| 110 | 139 | for bian in bians: |
| 111 | 140 | |
| 112 | 141 | bian_ext = bian.GetEnvelope() |
| 113 | - | |
| 114 | - query_result = rtree.query(env2rect(bian_ext)) | |
| 142 | + query_result = list(rtree.query(env2rect(bian_ext))) | |
| 115 | 143 | |
| 116 | 144 | intersection_data = [] |
| 117 | 145 | |
| 118 | - | |
| 119 | 146 | for entry in query_result: |
| 120 | 147 | |
| 121 | 148 | # 已被抛弃的不要 |
| ... | ... | @@ -123,67 +150,65 @@ class PolygonMerge: |
| 123 | 150 | continue |
| 124 | 151 | intersection_geom: Geometry = bian.Intersection(entry.data.triangle) |
| 125 | 152 | |
| 153 | + | |
| 126 | 154 | if not intersection_geom.IsEmpty(): |
| 127 | 155 | if not intersection_geom.Equals(bian): |
| 128 | 156 | if intersection_geom.GetGeometryType() in [2, 5, -2147483643, -2147483646, 3002, 3005]: |
| 129 | 157 | intersection_data.append(entry.data) |
| 130 | 158 | |
| 131 | 159 | |
| 160 | + | |
| 132 | 161 | for data in intersection_data: |
| 133 | 162 | data.set_state(0) |
| 134 | 163 | |
| 135 | 164 | if intersection_data: |
| 136 | 165 | |
| 166 | + | |
| 137 | 167 | inter_tri_merge:Geometry = intersection_data[0].triangle |
| 138 | 168 | |
| 139 | 169 | for ind in range(1,len(intersection_data)): |
| 140 | 170 | inter_tri_merge = inter_tri_merge.Union(intersection_data[ind].triangle) |
| 141 | 171 | |
| 172 | + try: | |
| 173 | + inter_tri_merge_line:Geometry = cls.get_polygon_lines(inter_tri_merge) | |
| 142 | 174 | |
| 143 | - inter_tri_merge_line:Geometry = cls.get_polygon_lines(inter_tri_merge) | |
| 144 | - | |
| 145 | - inter_tri_merge_line_points:list = inter_tri_merge_line.GetPoints() | |
| 175 | + inter_tri_merge_line_points:list = inter_tri_merge_line.GetPoints() | |
| 146 | 176 | |
| 147 | - bian_ps = bian.GetPoints() | |
| 177 | + bian_ps = bian.GetPoints() | |
| 148 | 178 | |
| 149 | - if len(inter_tri_merge_line_points[0]) == 3: | |
| 150 | - try: | |
| 179 | + if len(inter_tri_merge_line_points[0]) == 3: | |
| 151 | 180 | first_index = inter_tri_merge_line_points.index(bian_ps[0]) |
| 152 | 181 | second_index = inter_tri_merge_line_points.index(bian_ps[1]) |
| 153 | - except: | |
| 154 | - rtree.insert(RTreeData(inter_tri_merge, 1), env2rect(inter_tri_merge.GetEnvelope())) | |
| 155 | - continue | |
| 156 | - else: | |
| 157 | - try: | |
| 182 | + else: | |
| 183 | + | |
| 158 | 184 | first_index = inter_tri_merge_line_points.index((bian_ps[0][0],bian_ps[0][1])) |
| 159 | 185 | second_index = inter_tri_merge_line_points.index((bian_ps[1][0],bian_ps[1][1])) |
| 160 | - except: | |
| 161 | - rtree.insert(RTreeData(inter_tri_merge, 1), env2rect(inter_tri_merge.GetEnvelope())) | |
| 162 | - continue | |
| 163 | 186 | |
| 187 | + small_index = min(first_index,second_index) | |
| 188 | + big_index = max(first_index,second_index) | |
| 164 | 189 | |
| 190 | + small_points:list = inter_tri_merge_line_points[:small_index+1] | |
| 191 | + small_points.extend(inter_tri_merge_line_points[big_index:]) | |
| 192 | + small_polygon:Geometry = cls.create_polygon(small_points) | |
| 165 | 193 | |
| 166 | - small_index = min(first_index,second_index) | |
| 167 | - big_index = max(first_index,second_index) | |
| 194 | + delauney = cls.get_delauney(small_polygon) | |
| 195 | + for de in delauney: | |
| 196 | + de_extent = de.GetEnvelope() | |
| 197 | + rtree.insert(RTreeData(de, 1), env2rect(de_extent)) | |
| 168 | 198 | |
| 169 | - small_points:list = inter_tri_merge_line_points[:small_index+1] | |
| 170 | - small_points.extend(inter_tri_merge_line_points[big_index:]) | |
| 171 | - small_polygon:Geometry = cls.create_polygon(small_points) | |
| 199 | + big_points = inter_tri_merge_line_points[small_index:big_index+1] | |
| 200 | + big_points.append(inter_tri_merge_line_points[small_index]) | |
| 172 | 201 | |
| 173 | - delauney = cls.get_delauney(small_polygon) | |
| 174 | - for de in delauney: | |
| 175 | - de_extent = de.GetEnvelope() | |
| 176 | - rtree.insert(RTreeData(de, 1), env2rect(de_extent)) | |
| 202 | + big_polygon:Geometry = cls.create_polygon(big_points) | |
| 177 | 203 | |
| 178 | - big_points = inter_tri_merge_line_points[small_index:big_index+1] | |
| 179 | - big_points.append(inter_tri_merge_line_points[small_index]) | |
| 204 | + delauney = cls.get_delauney(big_polygon) | |
| 205 | + for de in delauney: | |
| 206 | + de_extent = de.GetEnvelope() | |
| 207 | + rtree.insert(RTreeData(de, 1), env2rect(de_extent)) | |
| 208 | + except: | |
| 209 | + print(inter_tri_merge) | |
| 210 | + print(bian) | |
| 180 | 211 | |
| 181 | - big_polygon:Geometry = cls.create_polygon(big_points) | |
| 182 | - | |
| 183 | - delauney = cls.get_delauney(big_polygon) | |
| 184 | - for de in delauney: | |
| 185 | - de_extent = de.GetEnvelope() | |
| 186 | - rtree.insert(RTreeData(de, 1), env2rect(de_extent)) | |
| 187 | 212 | |
| 188 | 213 | for entry in rtree.get_leaf_entries(): |
| 189 | 214 | triangle = entry.data.triangle |
| ... | ... | @@ -192,42 +217,176 @@ class PolygonMerge: |
| 192 | 217 | if polygon.Contains(triangle): |
| 193 | 218 | pass |
| 194 | 219 | else: |
| 195 | - tri_center,tri_center2 = cls.get_center(triangle) | |
| 196 | - distance = tri_center.Distance(polygon) | |
| 197 | - distance2 = tri_center2.Distance(polygon) | |
| 220 | + centers = cls.get_center(triangle) | |
| 221 | + # querycenter :Geometry= tri_center.Buffer(distance_buffer_threshold) | |
| 222 | + | |
| 223 | + # query_result = list(rtree.query(env2rect(querycenter.GetEnvelope()))) | |
| 224 | + | |
| 225 | + pass_ = False | |
| 226 | + for center in centers: | |
| 227 | + distance = center.Distance(polygon) | |
| 228 | + if distance > distance_buffer_threshold : | |
| 229 | + pass_ = True | |
| 230 | + break | |
| 198 | 231 | |
| 199 | - if distance > distance_buffer_threshold : | |
| 232 | + if pass_: | |
| 200 | 233 | continue |
| 201 | - # if distance2 > distance_buffer_threshold: | |
| 234 | + | |
| 235 | + # if len(query_result)==0: | |
| 202 | 236 | # continue |
| 237 | + polygon:Geometry = polygon.Union(triangle) | |
| 203 | 238 | |
| 204 | - polygon = polygon.Union(triangle) | |
| 205 | 239 | # polygon.AddGeometry(triangle) |
| 206 | 240 | |
| 207 | - result :Geometry = polygon | |
| 241 | + # result: Geometry = polygon | |
| 242 | + | |
| 243 | + # 去岛 | |
| 244 | + result :Geometry = cls.remove_hole(polygon,distance_buffer_threshold) | |
| 208 | 245 | |
| 209 | 246 | return result |
| 210 | 247 | |
| 248 | + @classmethod | |
| 249 | + def remove_hole(cls,polygon:Geometry,distance_buffer_threshold): | |
| 250 | + | |
| 251 | + polygons = [] | |
| 252 | + | |
| 253 | + if polygon.GetGeometryType() in [6, -2147483642, 3006]: | |
| 254 | + for index in range(polygon.GetGeometryCount()): | |
| 255 | + each = polygon.GetGeometryRef(index) | |
| 256 | + polygons.append(each) | |
| 257 | + else: | |
| 258 | + polygons.append(polygon) | |
| 259 | + | |
| 260 | + polygons = [cls.remove_hole_simple(p,distance_buffer_threshold) for p in polygons] | |
| 261 | + | |
| 262 | + if len(polygons) == 1: | |
| 263 | + return polygons[0] | |
| 264 | + else: | |
| 265 | + mp:Geometry = ogr.Geometry(ogr.wkbMultiPolygon) | |
| 266 | + for p in polygons: | |
| 267 | + mp.AddGeometry(p) | |
| 268 | + return mp | |
| 211 | 269 | |
| 212 | 270 | @classmethod |
| 213 | - def get_center(cls,tri:Geometry): | |
| 271 | + def remove_hole_simple(cls,polygon:Geometry,distance_buffer_threshold): | |
| 272 | + | |
| 273 | + if polygon.GetGeometryCount() >1: | |
| 274 | + for index in range(1,polygon.GetGeometryCount()): | |
| 275 | + | |
| 276 | + each:Geometry = copy.deepcopy(polygon.GetGeometryRef(index)) | |
| 277 | + | |
| 278 | + if each.GetArea() < distance_buffer_threshold*distance_buffer_threshold*5: | |
| 279 | + polygon.RemoveGeometry(index) | |
| 280 | + cls.remove_hole_simple(polygon,distance_buffer_threshold) | |
| 281 | + break | |
| 282 | + | |
| 283 | + return polygon | |
| 284 | + | |
| 285 | + @classmethod | |
| 286 | + def remove_hole_simple2(cls,polygon:Geometry,distance_buffer_threshold): | |
| 287 | + | |
| 288 | + if polygon.GetGeometryCount() >1: | |
| 289 | + for index in range(1,polygon.GetGeometryCount()): | |
| 290 | + | |
| 291 | + each:Geometry = polygon.GetGeometryRef(index) | |
| 292 | + print(polygon.GetGeometryCount()) | |
| 293 | + if each: | |
| 294 | + if each.GetArea() < distance_buffer_threshold*distance_buffer_threshold*18: | |
| 295 | + polygon.RemoveGeometry(index) | |
| 296 | + | |
| 297 | + return polygon | |
| 298 | + | |
| 299 | + @classmethod | |
| 300 | + def get_center2(cls,tri:Geometry): | |
| 301 | + | |
| 302 | + tri_line: Geometry = cls.get_polygon_lines(tri) | |
| 303 | + tri_line_points = tri_line.GetPoints() | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + max = 0 | |
| 308 | + poi_tuple = [] | |
| 309 | + | |
| 310 | + | |
| 311 | + center1 = ogr.Geometry(ogr.wkbPoint) | |
| 312 | + center2 = ogr.Geometry(ogr.wkbPoint) | |
| 313 | + center3 = ogr.Geometry(ogr.wkbPoint) | |
| 314 | + | |
| 315 | + | |
| 316 | + for index in range(len(tri_line_points)-1): | |
| 317 | + | |
| 318 | + first = tri_line_points[index] | |
| 319 | + second = tri_line_points[index+1] | |
| 320 | + | |
| 321 | + dis = math.sqrt(math.pow(first[0]-second[0],2) + math.pow(first[1]-second[1],2)) | |
| 322 | + | |
| 323 | + if dis > max: | |
| 324 | + max = dis | |
| 325 | + poi_tuple = [first, second] | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + center1.AddPoint((poi_tuple[0][0]+poi_tuple[1][0])/2,(poi_tuple[0][1]+poi_tuple[1][1])/2) | |
| 330 | + center2.AddPoint((poi_tuple[0][0] + center1.GetX()) / 2, (poi_tuple[0][1] + center1.GetY()) / 2) | |
| 331 | + center3.AddPoint((poi_tuple[1][0] + center1.GetX()) / 2, (poi_tuple[1][1] + center1.GetY()) / 2) | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + return [center1,center2,center3] | |
| 336 | + | |
| 337 | + @classmethod | |
| 338 | + def get_center(cls, tri: Geometry): | |
| 339 | + | |
| 340 | + center_set = set() | |
| 214 | 341 | |
| 215 | 342 | tri_line: Geometry = cls.get_polygon_lines(tri) |
| 216 | 343 | tri_line_points = tri_line.GetPoints() |
| 217 | 344 | |
| 218 | - lines = [] | |
| 345 | + | |
| 346 | + | |
| 347 | + max = 0 | |
| 348 | + poi_tuple = [] | |
| 349 | + | |
| 350 | + | |
| 351 | + center1 = ogr.Geometry(ogr.wkbPoint) | |
| 352 | + center2 = ogr.Geometry(ogr.wkbPoint) | |
| 353 | + center3 = ogr.Geometry(ogr.wkbPoint) | |
| 354 | + | |
| 219 | 355 | |
| 220 | 356 | for index in range(len(tri_line_points)-1): |
| 357 | + | |
| 221 | 358 | first = tri_line_points[index] |
| 222 | 359 | second = tri_line_points[index+1] |
| 223 | - line: Geometry = ogr.Geometry(ogr.wkbLineString) | |
| 224 | - line.AddPoint(first[0], first[1]) | |
| 225 | - line.AddPoint(second[0], second[1]) | |
| 226 | - lines.append(line) | |
| 227 | 360 | |
| 228 | - lines = sorted(lines,key=lambda l:l.Length()) | |
| 361 | + dis = math.sqrt(math.pow(first[0]-second[0],2) + math.pow(first[1]-second[1],2)) | |
| 362 | + | |
| 363 | + if dis > max: | |
| 364 | + max = dis | |
| 365 | + poi_tuple = [first, second] | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + center1.AddPoint((poi_tuple[0][0]+poi_tuple[1][0])/2,(poi_tuple[0][1]+poi_tuple[1][1])/2) | |
| 370 | + center2.AddPoint((poi_tuple[0][0] + center1.GetX()) / 2, (poi_tuple[0][1] + center1.GetY()) / 2) | |
| 371 | + center3.AddPoint((poi_tuple[1][0] + center1.GetX()) / 2, (poi_tuple[1][1] + center1.GetY()) / 2) | |
| 372 | + | |
| 373 | + center_set.add(center1) | |
| 374 | + center_set.add(center2) | |
| 375 | + center_set.add(center3) | |
| 229 | 376 | |
| 230 | - return lines[-1].Centroid(),lines[-2].Centroid() | |
| 377 | + center4 = ogr.Geometry(ogr.wkbPoint) | |
| 378 | + center5 = ogr.Geometry(ogr.wkbPoint) | |
| 379 | + center6 = ogr.Geometry(ogr.wkbPoint) | |
| 380 | + | |
| 381 | + center4.AddPoint((tri_line_points[0][0] + tri_line_points[1][0]) / 2, (tri_line_points[0][1] + tri_line_points[1][1]) / 2) | |
| 382 | + center5.AddPoint((tri_line_points[1][0] + tri_line_points[2][0]) / 2, (tri_line_points[1][1] + tri_line_points[2][1]) / 2) | |
| 383 | + center6.AddPoint((tri_line_points[2][0] + tri_line_points[3][0]) / 2, (tri_line_points[2][1] + tri_line_points[3][1]) / 2) | |
| 384 | + | |
| 385 | + center_set.add(center4) | |
| 386 | + center_set.add(center5) | |
| 387 | + center_set.add(center6) | |
| 388 | + | |
| 389 | + return center_set | |
| 231 | 390 | |
| 232 | 391 | @classmethod |
| 233 | 392 | def get_polygon_lines(cls,polygon): |
| ... | ... | @@ -289,32 +448,17 @@ if __name__ == '__main__': |
| 289 | 448 | t1 = time.time() |
| 290 | 449 | |
| 291 | 450 | |
| 292 | - # sd = ShapeData(r"J:\Data\制图综合result\t4.shp") | |
| 293 | - # mp = ogr.Geometry(ogr.wkbMultiPolygon) | |
| 294 | - # polygons = sd.get_polygons() | |
| 295 | - # | |
| 296 | - # wkts = PolygonMerge.merge(polygons) | |
| 297 | - # | |
| 298 | - # result = r"J:\Data\制图综合result\t4_merge.shp" | |
| 299 | - # | |
| 300 | - # ShapeData.create_shp_fromwkts(result,"zh",wkts) | |
| 301 | - # | |
| 302 | - # print(time.time()-t1) | |
| 451 | + sd = ShapeData(r"J:\Data\论文\rh.shp") | |
| 452 | + | |
| 453 | + polygons = sd.get_polygons() | |
| 454 | + | |
| 455 | + p_rh = [PolygonMerge.remove_hole(p,1.114691025217302e-04) for p in polygons] | |
| 303 | 456 | |
| 457 | + wkts = [p.ExportToWkt() for p in p_rh] | |
| 304 | 458 | |
| 305 | - p = PolygonMerge.create_polygon([(113.37029204400005, 22.526576828100076, 0.0), (113.36972403800007, 22.526369320699985, 0.0), (113.36974547200009, 22.526379207800005, 0.0), (113.37025989200004, 22.52656695200011, 0.0), (113.37029204400005, 22.526576828100076, 0.0)]) | |
| 459 | + result = r"J:\Data\论文\rhresult.shp" | |
| 306 | 460 | |
| 307 | - pl:Geometry = ogr.ForceToLineString(p) | |
| 461 | + ShapeData.create_shp_fromwkts(result,"zh",wkts) | |
| 308 | 462 | |
| 309 | - ps:list = pl.GetPoints() | |
| 310 | - ps.reverse() | |
| 311 | 463 | |
| 312 | - PolygonMerge.get_tri(ps) | |
| 313 | 464 | |
| 314 | - # wkts =[p.ExportToWkt()] | |
| 315 | - # | |
| 316 | - # result = r"J:\Data\制图综合result\error.shp" | |
| 317 | - # | |
| 318 | - # ShapeData.create_shp_fromwkts(result,"zh",wkts) | |
| 319 | - # | |
| 320 | - # print(time.time()-t1) | |
| \ No newline at end of file | ... | ... |
请
注册
或
登录
后发表评论