evo-data-converters-shp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- evo_data_converters_shp-0.1.0/.gitignore +140 -0
- evo_data_converters_shp-0.1.0/LICENSE.md +190 -0
- evo_data_converters_shp-0.1.0/PKG-INFO +82 -0
- evo_data_converters_shp-0.1.0/README.md +65 -0
- evo_data_converters_shp-0.1.0/pyproject.toml +58 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/__init__.py +0 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/exceptions.py +14 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/__init__.py +0 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/local_data.py +45 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/mesh_builder.py +301 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/prj_parser.py +26 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/shp_parser.py +81 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/triangles_builder.py +148 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/utils.py +34 -0
- evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/shp_to_evo.py +91 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.pyc
|
|
6
|
+
|
|
7
|
+
# C extensions
|
|
8
|
+
*.so
|
|
9
|
+
|
|
10
|
+
# Distribution / packaging
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
pip-wheel-metadata/
|
|
25
|
+
share/python-wheels/
|
|
26
|
+
*.egg-info/
|
|
27
|
+
.installed.cfg
|
|
28
|
+
*.egg
|
|
29
|
+
MANIFEST
|
|
30
|
+
|
|
31
|
+
# PyInstaller
|
|
32
|
+
# Usually these files are written by a python script from a template
|
|
33
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
34
|
+
*.manifest
|
|
35
|
+
*.spec
|
|
36
|
+
|
|
37
|
+
# Installer logs
|
|
38
|
+
pip-log.txt
|
|
39
|
+
pip-delete-this-directory.txt
|
|
40
|
+
|
|
41
|
+
# Unit test / coverage reports
|
|
42
|
+
htmlcov/
|
|
43
|
+
.tox/
|
|
44
|
+
.nox/
|
|
45
|
+
.coverage
|
|
46
|
+
.coverage.*
|
|
47
|
+
.cache
|
|
48
|
+
nosetests.xml
|
|
49
|
+
coverage.xml
|
|
50
|
+
*.cover
|
|
51
|
+
*.py,cover
|
|
52
|
+
.hypothesis/
|
|
53
|
+
.pytest_cache/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pipenv
|
|
86
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
87
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
88
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
89
|
+
# install all needed dependencies.
|
|
90
|
+
#Pipfile.lock
|
|
91
|
+
|
|
92
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
93
|
+
__pypackages__/
|
|
94
|
+
|
|
95
|
+
# Celery stuff
|
|
96
|
+
celerybeat-schedule
|
|
97
|
+
celerybeat.pid
|
|
98
|
+
|
|
99
|
+
# SageMath parsed files
|
|
100
|
+
*.sage.py
|
|
101
|
+
|
|
102
|
+
# Environments
|
|
103
|
+
.env
|
|
104
|
+
.venv
|
|
105
|
+
example_virtual_env
|
|
106
|
+
env/
|
|
107
|
+
venv/
|
|
108
|
+
ENV/
|
|
109
|
+
env.bak/
|
|
110
|
+
venv.bak/
|
|
111
|
+
|
|
112
|
+
# Spyder project settings
|
|
113
|
+
.spyderproject
|
|
114
|
+
.spyproject
|
|
115
|
+
|
|
116
|
+
# Rope project settings
|
|
117
|
+
.ropeproject
|
|
118
|
+
|
|
119
|
+
# mkdocs documentation
|
|
120
|
+
/site
|
|
121
|
+
|
|
122
|
+
# mypy
|
|
123
|
+
.mypy_cache/
|
|
124
|
+
.dmypy.json
|
|
125
|
+
dmypy.json
|
|
126
|
+
|
|
127
|
+
# Pyre type checker
|
|
128
|
+
.pyre/
|
|
129
|
+
|
|
130
|
+
# Custom
|
|
131
|
+
.idea
|
|
132
|
+
query_results.parquet
|
|
133
|
+
.cache_ggshield
|
|
134
|
+
|
|
135
|
+
# Object data client caches
|
|
136
|
+
samples/data-converters/python/convert-omf/data/cache
|
|
137
|
+
data/cache
|
|
138
|
+
|
|
139
|
+
# Development tools
|
|
140
|
+
.vscode/
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
Apache License
|
|
16
|
+
Version 2.0, January 2004
|
|
17
|
+
http://www.apache.org/licenses/
|
|
18
|
+
|
|
19
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
20
|
+
|
|
21
|
+
1. Definitions.
|
|
22
|
+
|
|
23
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
24
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
25
|
+
|
|
26
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
27
|
+
the copyright owner that is granting the License.
|
|
28
|
+
|
|
29
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
30
|
+
other entities that control, are controlled by, or are under common
|
|
31
|
+
control with that entity. For the purposes of this definition,
|
|
32
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
33
|
+
direction or management of such entity, whether by contract or
|
|
34
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
35
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
36
|
+
|
|
37
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
38
|
+
exercising permissions granted by this License.
|
|
39
|
+
|
|
40
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
41
|
+
including but not limited to software source code, documentation
|
|
42
|
+
source, and configuration files.
|
|
43
|
+
|
|
44
|
+
"Object" form shall mean any form resulting from mechanical
|
|
45
|
+
transformation or translation of a Source form, including but
|
|
46
|
+
not limited to compiled object code, generated documentation,
|
|
47
|
+
and conversions to other media types.
|
|
48
|
+
|
|
49
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
50
|
+
Object form, made available under the License, as indicated by a
|
|
51
|
+
copyright notice that is included in or attached to the work
|
|
52
|
+
(an example is provided in the Appendix below).
|
|
53
|
+
|
|
54
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
55
|
+
form, that is based on (or derived from) the Work and for which the
|
|
56
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
57
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
58
|
+
of this License, Derivative Works shall not include works that remain
|
|
59
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
60
|
+
the Work and Derivative Works thereof.
|
|
61
|
+
|
|
62
|
+
"Contribution" shall mean any work of authorship, including
|
|
63
|
+
the original version of the Work and any modifications or additions
|
|
64
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
65
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
66
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
67
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
68
|
+
means any form of electronic, verbal, or written communication sent
|
|
69
|
+
to the Licensor or its representatives, including but not limited to
|
|
70
|
+
communication on electronic mailing lists, source code control systems,
|
|
71
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
72
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
73
|
+
excluding communication that is conspicuously marked or otherwise
|
|
74
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
75
|
+
|
|
76
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
77
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
78
|
+
subsequently incorporated within the Work.
|
|
79
|
+
|
|
80
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
81
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
84
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
85
|
+
Work and such Derivative Works in Source or Object form.
|
|
86
|
+
|
|
87
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
88
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
89
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
90
|
+
(except as stated in this section) patent license to make, have made,
|
|
91
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
92
|
+
where such license applies only to those patent claims licensable
|
|
93
|
+
by such Contributor that are necessarily infringed by their
|
|
94
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
95
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
96
|
+
institute patent litigation against any entity (including a
|
|
97
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
98
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
99
|
+
or contributory patent infringement, then any patent licenses
|
|
100
|
+
granted to You under this License for that Work shall terminate
|
|
101
|
+
as of the date such litigation is filed.
|
|
102
|
+
|
|
103
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
104
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
105
|
+
modifications, and in Source or Object form, provided that You
|
|
106
|
+
meet the following conditions:
|
|
107
|
+
|
|
108
|
+
(a) You must give any other recipients of the Work or
|
|
109
|
+
Derivative Works a copy of this License; and
|
|
110
|
+
|
|
111
|
+
(b) You must cause any modified files to carry prominent notices
|
|
112
|
+
stating that You changed the files; and
|
|
113
|
+
|
|
114
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
115
|
+
that You distribute, all copyright, patent, trademark, and
|
|
116
|
+
attribution notices from the Source form of the Work,
|
|
117
|
+
excluding those notices that do not pertain to any part of
|
|
118
|
+
the Derivative Works; and
|
|
119
|
+
|
|
120
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
121
|
+
distribution, then any Derivative Works that You distribute must
|
|
122
|
+
include a readable copy of the attribution notices contained
|
|
123
|
+
within such NOTICE file, excluding those notices that do not
|
|
124
|
+
pertain to any part of the Derivative Works, in at least one
|
|
125
|
+
of the following places: within a NOTICE text file distributed
|
|
126
|
+
as part of the Derivative Works; within the Source form or
|
|
127
|
+
documentation, if provided along with the Derivative Works; or,
|
|
128
|
+
within a display generated by the Derivative Works, if and
|
|
129
|
+
wherever such third-party notices normally appear. The contents
|
|
130
|
+
of the NOTICE file are for informational purposes only and
|
|
131
|
+
do not modify the License. You may add Your own attribution
|
|
132
|
+
notices within Derivative Works that You distribute, alongside
|
|
133
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
134
|
+
that such additional attribution notices cannot be construed
|
|
135
|
+
as modifying the License.
|
|
136
|
+
|
|
137
|
+
You may add Your own copyright statement to Your modifications and
|
|
138
|
+
may provide additional or different license terms and conditions
|
|
139
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
140
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
141
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
142
|
+
the conditions stated in this License.
|
|
143
|
+
|
|
144
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
145
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
146
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
147
|
+
this License, without any additional terms or conditions.
|
|
148
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
149
|
+
the terms of any separate license agreement you may have executed
|
|
150
|
+
with Licensor regarding such Contributions.
|
|
151
|
+
|
|
152
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
153
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
154
|
+
except as required for reasonable and customary use in describing the
|
|
155
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
156
|
+
|
|
157
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
158
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
159
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
160
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
161
|
+
implied, including, without limitation, any warranties or conditions
|
|
162
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
163
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
164
|
+
appropriateness of using or redistributing the Work and assume any
|
|
165
|
+
risks associated with Your exercise of permissions under this License.
|
|
166
|
+
|
|
167
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
168
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
169
|
+
unless required by applicable law (such as deliberate and grossly
|
|
170
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
171
|
+
liable to You for damages, including any direct, indirect, special,
|
|
172
|
+
incidental, or consequential damages of any character arising as a
|
|
173
|
+
result of this License or out of the use or inability to use the
|
|
174
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
175
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
176
|
+
other commercial damages or losses), even if such Contributor
|
|
177
|
+
has been advised of the possibility of such damages.
|
|
178
|
+
|
|
179
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
180
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
181
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
182
|
+
or other liability obligations and/or rights consistent with this
|
|
183
|
+
License. However, in accepting such obligations, You may act only
|
|
184
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
185
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
186
|
+
defend, and hold each Contributor harmless for any liability
|
|
187
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
188
|
+
of your accepting any such warranty or additional liability.
|
|
189
|
+
|
|
190
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evo-data-converters-shp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python data converters for ESRI shapefiles to Evo geoscience objects.
|
|
5
|
+
Project-URL: Source, https://github.com/SeequentEvo/evo-data-converters
|
|
6
|
+
Project-URL: Tracker, https://github.com/SeequentEvo/evo-data-converters/issues
|
|
7
|
+
Project-URL: Homepage, https://www.seequent.com/
|
|
8
|
+
Project-URL: Documentation, https://developer.seequent.com/
|
|
9
|
+
Author-email: Seequent <support@seequent.com>
|
|
10
|
+
License-File: LICENSE.md
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Requires-Dist: evo-data-converters-common
|
|
13
|
+
Requires-Dist: evo-schemas>=2025.12.15
|
|
14
|
+
Requires-Dist: pyarrow>=21.0.0
|
|
15
|
+
Requires-Dist: pyshp>=3.0.3
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
<p align="center"><a href="https://seequent.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://developer.seequent.com/img/seequent-logo-dark.svg" alt="Seequent logo" width="400" /><img src="https://developer.seequent.com/img/seequent-logo.svg" alt="Seequent logo" width="400" /></picture></a></p>
|
|
19
|
+
<p align="center">
|
|
20
|
+
<a href="https://pypi.org/project/evo-data-converters-obj/"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/evo-data-converters-obj" /></a>
|
|
21
|
+
<a href="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml"><img src="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml/badge.svg" alt="" /></a>
|
|
22
|
+
</p>
|
|
23
|
+
<p align="center">
|
|
24
|
+
<a href="https://developer.seequent.com/" target="_blank">Seequent Developer Portal</a>
|
|
25
|
+
• <a href="https://community.seequent.com/group/19-evo" target="_blank">Seequent Community</a>
|
|
26
|
+
• <a href="https://seequent.com" target="_blank">Seequent website</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
## Evo
|
|
30
|
+
|
|
31
|
+
Evo is a unified platform for geoscience teams. It enables access, connection, computation, and management of subsurface data. This empowers better decision-making, simplified collaboration, and accelerated innovation. Evo is built on open APIs, allowing developers to build custom integrations and applications. Our open schemas, code examples, and SDK are available for the community to use and extend.
|
|
32
|
+
|
|
33
|
+
Evo is powered by Seequent, a Bentley organisation.
|
|
34
|
+
|
|
35
|
+
## Pre-requisites
|
|
36
|
+
|
|
37
|
+
* Python virtual environment with Python 3.10, 3.11, or 3.12
|
|
38
|
+
* Git
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
`pip install evo-data-converters-shp`
|
|
43
|
+
|
|
44
|
+
## Shapefiles
|
|
45
|
+
|
|
46
|
+
A shapefile is a set of files which can contain points, lines, and polygons with associated attributes. At minimum, it consists of a main .shp file, an index .shx file, and a dBASE .dbf file.
|
|
47
|
+
|
|
48
|
+
Refer to this page for more information: https://desktop.arcgis.com/en/arcmap/latest/manage-data/shapefiles/what-is-a-shapefile.htm or view the technical specification here: https://www.esri.com/content/dam/esrisites/sitecore-archive/Files/Pdfs/library/whitepapers/pdfs/shapefile.pdf
|
|
49
|
+
|
|
50
|
+
### Multipatch Shapefiles
|
|
51
|
+
There are multiple shape types which can be used to define a shapefile, though all (non-null) shapes in a given file must be of the same type. Multipatch shapes consist of triangles (defined as 'triangle strips' or 'triangle fans') and rings.
|
|
52
|
+
|
|
53
|
+
### Implementations
|
|
54
|
+
|
|
55
|
+
The python [pyshp](https://pypi.org/project/pyshp/) package is used to work with shapefiles.
|
|
56
|
+
|
|
57
|
+
The SHP converter currently only supports importing multipatch shapefiles which do not contain any rings. These are translated to the triangle-mesh schema and published to an Evo workspace. NULL shapes are discarded.
|
|
58
|
+
|
|
59
|
+
### Publish geoscience objects from ESRI Shapefile files
|
|
60
|
+
|
|
61
|
+
[The `evo-sdk-common` Python library](https://github.com/SeequentEvo/evo-data-converters/tree/main/packages/common) can be used to sign in. After successfully signing in, the user can select an organisation, an Evo hub, and a workspace. Use [`evo-objects`](https://github.com/SeequentEvo/evo-python-sdk/tree/main/packages/evo-objects) to get an `ObjectAPIClient`, and [`evo-data-converters-shp`](https://github.com/SeequentEvo/evo-data-converters/tree/main/packages/shp) to convert your file.
|
|
62
|
+
|
|
63
|
+
Have a look at the `code-samples/convert-shp.ipynb` notebook for an example of how to publish shapefiles.
|
|
64
|
+
|
|
65
|
+
## Code of conduct
|
|
66
|
+
|
|
67
|
+
We rely on an open, friendly, inclusive environment. To help us ensure this remains possible, please familiarise yourself with our [code of conduct.](https://github.com/SeequentEvo/evo-data-converters/blob/main/CODE_OF_CONDUCT.md)
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
Evo data converters are open source and licensed under the [Apache 2.0 license.](./LICENSE.md)
|
|
71
|
+
|
|
72
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
73
|
+
|
|
74
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
75
|
+
You may obtain a copy of the License at
|
|
76
|
+
|
|
77
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
78
|
+
|
|
79
|
+
Unless required by applicable law or agreed to in writing, software
|
|
80
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
81
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
82
|
+
See the License for the specific language governing permissions and
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<p align="center"><a href="https://seequent.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://developer.seequent.com/img/seequent-logo-dark.svg" alt="Seequent logo" width="400" /><img src="https://developer.seequent.com/img/seequent-logo.svg" alt="Seequent logo" width="400" /></picture></a></p>
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://pypi.org/project/evo-data-converters-obj/"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/evo-data-converters-obj" /></a>
|
|
4
|
+
<a href="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml"><img src="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml/badge.svg" alt="" /></a>
|
|
5
|
+
</p>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://developer.seequent.com/" target="_blank">Seequent Developer Portal</a>
|
|
8
|
+
• <a href="https://community.seequent.com/group/19-evo" target="_blank">Seequent Community</a>
|
|
9
|
+
• <a href="https://seequent.com" target="_blank">Seequent website</a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
## Evo
|
|
13
|
+
|
|
14
|
+
Evo is a unified platform for geoscience teams. It enables access, connection, computation, and management of subsurface data. This empowers better decision-making, simplified collaboration, and accelerated innovation. Evo is built on open APIs, allowing developers to build custom integrations and applications. Our open schemas, code examples, and SDK are available for the community to use and extend.
|
|
15
|
+
|
|
16
|
+
Evo is powered by Seequent, a Bentley organisation.
|
|
17
|
+
|
|
18
|
+
## Pre-requisites
|
|
19
|
+
|
|
20
|
+
* Python virtual environment with Python 3.10, 3.11, or 3.12
|
|
21
|
+
* Git
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
`pip install evo-data-converters-shp`
|
|
26
|
+
|
|
27
|
+
## Shapefiles
|
|
28
|
+
|
|
29
|
+
A shapefile is a set of files which can contain points, lines, and polygons with associated attributes. At minimum, it consists of a main .shp file, an index .shx file, and a dBASE .dbf file.
|
|
30
|
+
|
|
31
|
+
Refer to this page for more information: https://desktop.arcgis.com/en/arcmap/latest/manage-data/shapefiles/what-is-a-shapefile.htm or view the technical specification here: https://www.esri.com/content/dam/esrisites/sitecore-archive/Files/Pdfs/library/whitepapers/pdfs/shapefile.pdf
|
|
32
|
+
|
|
33
|
+
### Multipatch Shapefiles
|
|
34
|
+
There are multiple shape types which can be used to define a shapefile, though all (non-null) shapes in a given file must be of the same type. Multipatch shapes consist of triangles (defined as 'triangle strips' or 'triangle fans') and rings.
|
|
35
|
+
|
|
36
|
+
### Implementations
|
|
37
|
+
|
|
38
|
+
The python [pyshp](https://pypi.org/project/pyshp/) package is used to work with shapefiles.
|
|
39
|
+
|
|
40
|
+
The SHP converter currently only supports importing multipatch shapefiles which do not contain any rings. These are translated to the triangle-mesh schema and published to an Evo workspace. NULL shapes are discarded.
|
|
41
|
+
|
|
42
|
+
### Publish geoscience objects from ESRI Shapefile files
|
|
43
|
+
|
|
44
|
+
[The `evo-sdk-common` Python library](https://github.com/SeequentEvo/evo-data-converters/tree/main/packages/common) can be used to sign in. After successfully signing in, the user can select an organisation, an Evo hub, and a workspace. Use [`evo-objects`](https://github.com/SeequentEvo/evo-python-sdk/tree/main/packages/evo-objects) to get an `ObjectAPIClient`, and [`evo-data-converters-shp`](https://github.com/SeequentEvo/evo-data-converters/tree/main/packages/shp) to convert your file.
|
|
45
|
+
|
|
46
|
+
Have a look at the `code-samples/convert-shp.ipynb` notebook for an example of how to publish shapefiles.
|
|
47
|
+
|
|
48
|
+
## Code of conduct
|
|
49
|
+
|
|
50
|
+
We rely on an open, friendly, inclusive environment. To help us ensure this remains possible, please familiarise yourself with our [code of conduct.](https://github.com/SeequentEvo/evo-data-converters/blob/main/CODE_OF_CONDUCT.md)
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
Evo data converters are open source and licensed under the [Apache 2.0 license.](./LICENSE.md)
|
|
54
|
+
|
|
55
|
+
Copyright © 2025 Bentley Systems, Incorporated.
|
|
56
|
+
|
|
57
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
58
|
+
You may obtain a copy of the License at
|
|
59
|
+
|
|
60
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
61
|
+
|
|
62
|
+
Unless required by applicable law or agreed to in writing, software
|
|
63
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
64
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
65
|
+
See the License for the specific language governing permissions and
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "evo-data-converters-shp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python data converters for ESRI shapefiles to Evo geoscience objects."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Seequent", email = "support@seequent.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"evo-data-converters-common",
|
|
12
|
+
"evo-schemas>=2025.12.15",
|
|
13
|
+
"pyarrow>=21.0.0",
|
|
14
|
+
"pyshp>=3.0.3",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Source = "https://github.com/SeequentEvo/evo-data-converters"
|
|
19
|
+
Tracker = "https://github.com/SeequentEvo/evo-data-converters/issues"
|
|
20
|
+
Homepage = "https://www.seequent.com/"
|
|
21
|
+
Documentation = "https://developer.seequent.com/"
|
|
22
|
+
|
|
23
|
+
[dependency-groups]
|
|
24
|
+
dev = [
|
|
25
|
+
"pytest"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.ruff]
|
|
29
|
+
src = ["src", "tests"]
|
|
30
|
+
line-length = 120
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
evo-data-converters-shp = "evo_data_converters_shp:main"
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["hatchling", "hatch-fancy-pypi-readme"]
|
|
37
|
+
build-backend = "hatchling.build"
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.sdist]
|
|
40
|
+
include = ["src"]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/evo"]
|
|
44
|
+
|
|
45
|
+
[tool.uv.sources]
|
|
46
|
+
evo-data-converters-common = { workspace = true }
|
|
47
|
+
|
|
48
|
+
[tool.hatch.metadata.hooks.fancy-pypi-readme]
|
|
49
|
+
content-type = "text/markdown"
|
|
50
|
+
|
|
51
|
+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
|
52
|
+
path = "README.md"
|
|
53
|
+
|
|
54
|
+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
|
|
55
|
+
# Literal TOML strings (single quotes) need no escaping of backslashes.
|
|
56
|
+
# Converts relative links to absolute links in PyPI
|
|
57
|
+
pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)'
|
|
58
|
+
replacement = '[\1](https://github.com/SeequentEvo/evo-data-converters/tree/main/packages/image/\g<2>)'
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright © 2026 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class InvalidSHPError(Exception):
|
|
14
|
+
"""Raised when the input SHP file is invalid or cannot be parsed."""
|
|
File without changes
|
evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/local_data.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright © 2026 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
import pathlib
|
|
12
|
+
|
|
13
|
+
import pyarrow as pa
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class LocalDataClient:
|
|
17
|
+
"""
|
|
18
|
+
A data client which saves to a local folder.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self, save_dir: str):
|
|
22
|
+
"""
|
|
23
|
+
Initalizes the local data client.
|
|
24
|
+
|
|
25
|
+
:param save_dir: The target directory of the data client. If it does not exist it will be created.
|
|
26
|
+
"""
|
|
27
|
+
path = pathlib.Path(save_dir)
|
|
28
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
29
|
+
self.save_dir = path if path.is_dir() else pathlib.Path(pathlib.Path.cwd(), "local_data")
|
|
30
|
+
|
|
31
|
+
def save_table(self, table: pa.Table) -> dict:
|
|
32
|
+
"""Save a pyarrow table to a file, returning the table info as a dictionary.
|
|
33
|
+
|
|
34
|
+
:param table: The pyarrow table to save.
|
|
35
|
+
|
|
36
|
+
:return: Information about the saved table.
|
|
37
|
+
|
|
38
|
+
:raises TableFormatError: If the provided table does not match this format.
|
|
39
|
+
:raises StorageFileNotFoundError: If the destination does not exist or is not a directory.
|
|
40
|
+
"""
|
|
41
|
+
from evo.objects.utils.table_formats import get_known_format
|
|
42
|
+
|
|
43
|
+
known_format = get_known_format(table)
|
|
44
|
+
table_info = known_format.save_table(table=table, destination=pathlib.Path(self.save_dir))
|
|
45
|
+
return table_info
|
evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/mesh_builder.py
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Copyright © 2026 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from collections.abc import Iterable
|
|
13
|
+
|
|
14
|
+
import pyarrow as pa
|
|
15
|
+
import shapefile
|
|
16
|
+
from evo.data_converters.shp.importer.exceptions import InvalidSHPError
|
|
17
|
+
from evo.data_converters.shp.importer.implementation.triangles_builder import TrianglesBuilder
|
|
18
|
+
from evo.data_converters.shp.importer.implementation.utils import date_to_evo_timestamp
|
|
19
|
+
from evo.objects.utils.data import ObjectDataClient
|
|
20
|
+
from evo_schemas.components import (
|
|
21
|
+
BoolAttribute_V1_1_0,
|
|
22
|
+
ContinuousAttribute_V1_1_0,
|
|
23
|
+
DateTimeAttribute_V1_1_0,
|
|
24
|
+
EmbeddedTriangulatedMesh_V2_1_0,
|
|
25
|
+
EmbeddedTriangulatedMesh_V2_1_0_Parts,
|
|
26
|
+
IntegerAttribute_V1_1_0,
|
|
27
|
+
NanCategorical_V1_0_1,
|
|
28
|
+
NanContinuous_V1_0_1,
|
|
29
|
+
OneOfAttribute_V1_2_0_Item,
|
|
30
|
+
StringAttribute_V1_1_0,
|
|
31
|
+
)
|
|
32
|
+
from evo_schemas.elements import (
|
|
33
|
+
BoolArray1_V1_0_1,
|
|
34
|
+
DateTimeArray_V1_0_1,
|
|
35
|
+
FloatArray1_V1_0_1,
|
|
36
|
+
IndexArray2_V1_0_1,
|
|
37
|
+
IntegerArray1_V1_0_1,
|
|
38
|
+
StringArray_V1_0_1,
|
|
39
|
+
)
|
|
40
|
+
from numpy import iinfo
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class MeshBuilder:
|
|
44
|
+
"""Uses pyshp ShapeRecords to build an EmbeddedTriangulatedMesh and associated objects."""
|
|
45
|
+
|
|
46
|
+
class _Mesh_Part_Data:
|
|
47
|
+
"""
|
|
48
|
+
Represents one set of attributes for the mesh parts.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
def __init__(self, nan_def, data_type: shapefile.FieldType):
|
|
52
|
+
"""
|
|
53
|
+
:param nan_def: The value of NaN for this data type.
|
|
54
|
+
:param data_type: The pyshp data type of this attruibute.
|
|
55
|
+
"""
|
|
56
|
+
self.nan_def = nan_def
|
|
57
|
+
self.data_type = data_type
|
|
58
|
+
self.data = []
|
|
59
|
+
|
|
60
|
+
data_client: ObjectDataClient
|
|
61
|
+
triangles_builder: TrianglesBuilder
|
|
62
|
+
mesh_parts: list[tuple[int, int]]
|
|
63
|
+
mesh_part_attributes: dict[str, _Mesh_Part_Data]
|
|
64
|
+
|
|
65
|
+
def __init__(self, data_client: ObjectDataClient, fields: Iterable[shapefile.Field]):
|
|
66
|
+
"""
|
|
67
|
+
Intialize the MeshBuilder.
|
|
68
|
+
|
|
69
|
+
:param data_client: Object data client for uploading parquet files (real or stub).
|
|
70
|
+
:param fields: A list of the shapefile fields and their data types.
|
|
71
|
+
"""
|
|
72
|
+
self.data_client = data_client
|
|
73
|
+
self.triangles_builder = TrianglesBuilder(data_client)
|
|
74
|
+
self.mesh_parts = []
|
|
75
|
+
self.mesh_part_attributes = {}
|
|
76
|
+
|
|
77
|
+
for field in fields:
|
|
78
|
+
self.mesh_part_attributes[field.name] = self._Mesh_Part_Data(
|
|
79
|
+
self._get_nan_def(field.field_type), field.field_type
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
def add_shape_record(self, shape_record: shapefile.ShapeRecord):
|
|
83
|
+
"""
|
|
84
|
+
Adds all triangles and attributes in the provided ShapeRecord to the mesh.
|
|
85
|
+
|
|
86
|
+
:param shape_record: The ShapeRecord to add.
|
|
87
|
+
|
|
88
|
+
:raise: InvalidSHPError if the shaperecord is not a multipatch or contains rings.
|
|
89
|
+
"""
|
|
90
|
+
shape = shape_record.shape
|
|
91
|
+
record = shape_record.record
|
|
92
|
+
|
|
93
|
+
# TODO: Need to figure out how to handle NULL shapes. These are 'shapes' which have associated data but no geometry. Perhaps storing them in a separate file is best? For now we discard them.
|
|
94
|
+
if shape.shapeType == shapefile.NULL:
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
# The last part extends to the end of the array, so we bookend it here for easier parsing.
|
|
98
|
+
parts = list(shape.parts) + [len(shape.points)]
|
|
99
|
+
points = self._shppoint_to_XYZ(shape.points, shape.z)
|
|
100
|
+
|
|
101
|
+
shape_start = self.triangles_builder.get_num_triangles()
|
|
102
|
+
shape_length = 0
|
|
103
|
+
|
|
104
|
+
for i in range(len(parts) - 1):
|
|
105
|
+
start = parts[i]
|
|
106
|
+
end = parts[i + 1]
|
|
107
|
+
partXYZ = points[start:end]
|
|
108
|
+
partM = shape.m[start:end]
|
|
109
|
+
match shape.partTypes[i]:
|
|
110
|
+
case shapefile.TRIANGLE_STRIP:
|
|
111
|
+
shape_length += self.add_triangle_strip(partXYZ, partM)
|
|
112
|
+
case shapefile.TRIANGLE_FAN:
|
|
113
|
+
shape_length += self.add_triangle_fan(partXYZ, partM)
|
|
114
|
+
case _:
|
|
115
|
+
raise InvalidSHPError(
|
|
116
|
+
"Provided shapefile contains rings. Only multipatch shapefiles without rings are supported."
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
record_dict = record.as_dict()
|
|
120
|
+
for key in self.mesh_part_attributes.keys():
|
|
121
|
+
value = record_dict.get(key)
|
|
122
|
+
# Convert dates to a microsecond timestamp.
|
|
123
|
+
if self.mesh_part_attributes[key].data_type == shapefile.FieldType.D:
|
|
124
|
+
value = date_to_evo_timestamp(value)
|
|
125
|
+
|
|
126
|
+
default = self.mesh_part_attributes[key].nan_def
|
|
127
|
+
self.mesh_part_attributes[key].data += [value if value is not None else default]
|
|
128
|
+
|
|
129
|
+
self.mesh_parts.append((shape_start, shape_length))
|
|
130
|
+
|
|
131
|
+
def add_triangle_strip(self, partXYZ: list[tuple[float, float, float]], partM: list[float | None]) -> int:
|
|
132
|
+
"""
|
|
133
|
+
Adds a list of points stored in triangle strip format and associated point data to the mesh. Triangle strips
|
|
134
|
+
are a set of points where every triple of consectuive points represents a triangle, so given points [a, b, c, d, e],
|
|
135
|
+
the triangles are a-b-c, b-c-d, and c-d-e.
|
|
136
|
+
|
|
137
|
+
:param partXYZ: Points stored in the triangle mesh format.
|
|
138
|
+
:params partM: Point data for every point. len(partM) == len(partXYZ)
|
|
139
|
+
|
|
140
|
+
:return: The number of triangles added.
|
|
141
|
+
"""
|
|
142
|
+
triangles_added = 0
|
|
143
|
+
for i in range(len(partXYZ) - 2):
|
|
144
|
+
self.triangles_builder.add_triangle(partXYZ[i : i + 3], partM[i : i + 3])
|
|
145
|
+
triangles_added += 1
|
|
146
|
+
|
|
147
|
+
return triangles_added
|
|
148
|
+
|
|
149
|
+
def add_triangle_fan(self, partXYZ: list[tuple[float, float, float]], partM: list[float | None]) -> int:
|
|
150
|
+
"""
|
|
151
|
+
Adds a list of points stored in triangle fan format and associated point data to the mesh. Triangle fans
|
|
152
|
+
are a set of points where every consecutive double of points forms a triangle with the first point, so
|
|
153
|
+
given points [a, b, c, d, e], the triangles are a-b-c, a-c-d, and a-d-e.
|
|
154
|
+
|
|
155
|
+
:param partXYZ: Points stored in the triangle mesh format.
|
|
156
|
+
:params partM: Point data for every point. len(partM) == len(partXYZ)
|
|
157
|
+
|
|
158
|
+
:return: The number of triangles added.
|
|
159
|
+
"""
|
|
160
|
+
assert len(partM) == len(partXYZ), (
|
|
161
|
+
"Not every point has a value (if a point has no value, an explicit None should be provided.)."
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
triangles_added = 0
|
|
165
|
+
center_vertex = partXYZ[0]
|
|
166
|
+
center_data = partM[0]
|
|
167
|
+
for i in range(1, len(partXYZ) - 1):
|
|
168
|
+
triangle = [center_vertex] + partXYZ[i : i + 2]
|
|
169
|
+
triangle_data = [center_data] + partM[i : i + 2]
|
|
170
|
+
self.triangles_builder.add_triangle(triangle, triangle_data)
|
|
171
|
+
triangles_added += 1
|
|
172
|
+
|
|
173
|
+
return triangles_added
|
|
174
|
+
|
|
175
|
+
def build(self) -> EmbeddedTriangulatedMesh_V2_1_0:
|
|
176
|
+
"""
|
|
177
|
+
Builds an EmbeddedTriangleMesh from the ShapeRecords added so far.
|
|
178
|
+
"""
|
|
179
|
+
attributes = []
|
|
180
|
+
for name, part in self.mesh_part_attributes.items():
|
|
181
|
+
attribute = self._attribute_from_mesh_part(name, part)
|
|
182
|
+
attributes.append(attribute)
|
|
183
|
+
|
|
184
|
+
# Mesh parts here do not correspond to shapefile 'parts' but instead shapefile 'shapes'. This is because records are per-shape.
|
|
185
|
+
offset, count = zip(*self.mesh_parts)
|
|
186
|
+
schema = pa.schema([("offset", pa.uint64()), ("count", pa.uint64())])
|
|
187
|
+
table = pa.table({"offset": offset, "count": count}, schema=schema)
|
|
188
|
+
chunk_hash = self._create_parquet_file(table)
|
|
189
|
+
chunks = IndexArray2_V1_0_1(data=chunk_hash, length=len(self.mesh_parts))
|
|
190
|
+
|
|
191
|
+
parts = EmbeddedTriangulatedMesh_V2_1_0_Parts(attributes=attributes, chunks=chunks)
|
|
192
|
+
|
|
193
|
+
triangles = self.triangles_builder.build()
|
|
194
|
+
|
|
195
|
+
return EmbeddedTriangulatedMesh_V2_1_0(triangles=triangles, parts=parts)
|
|
196
|
+
|
|
197
|
+
def _shppoint_to_XYZ(
|
|
198
|
+
self, points: Iterable[tuple[float, float]], z: Iterable[float]
|
|
199
|
+
) -> list[tuple[float, float, float]]:
|
|
200
|
+
"""
|
|
201
|
+
Converts points stored in the (x, y), z format of pyshp to (x, y, z) format for ease of use.
|
|
202
|
+
|
|
203
|
+
:param points: (x, y) coordinates of the points.
|
|
204
|
+
:param z: z values for the points. len(z) == len(x, y)
|
|
205
|
+
"""
|
|
206
|
+
assert len(points) == len(z), "Mismatched number of x, y, and z coordinates for shapefile points."
|
|
207
|
+
return [points[i] + (z[i],) for i in range(len(points))]
|
|
208
|
+
|
|
209
|
+
def _get_nan_def(self, field_type: shapefile.FieldType):
|
|
210
|
+
"""
|
|
211
|
+
Get an appropriate default NaN definition for the given pyshp FieldType.
|
|
212
|
+
|
|
213
|
+
:param field_type: pyshp field type.
|
|
214
|
+
|
|
215
|
+
:return: A NaN value for the given type (usually the minimum value).
|
|
216
|
+
"""
|
|
217
|
+
match field_type:
|
|
218
|
+
case shapefile.FieldType.N:
|
|
219
|
+
return iinfo("int64").min
|
|
220
|
+
case shapefile.FieldType.F:
|
|
221
|
+
return float("nan")
|
|
222
|
+
case shapefile.FieldType.D:
|
|
223
|
+
return iinfo("int64").min
|
|
224
|
+
case _:
|
|
225
|
+
return None
|
|
226
|
+
|
|
227
|
+
def _attribute_from_mesh_part(self, field_name: str, part: _Mesh_Part_Data) -> OneOfAttribute_V1_2_0_Item:
|
|
228
|
+
"""
|
|
229
|
+
Takes a mesh part and returns an appropriate geoscience object based on the field type.
|
|
230
|
+
|
|
231
|
+
:param field_name: The name of the field.
|
|
232
|
+
:param part: The data, NaN definition, and type of this part.
|
|
233
|
+
|
|
234
|
+
:return: A geoscience object representing the part.
|
|
235
|
+
"""
|
|
236
|
+
match part.data_type:
|
|
237
|
+
case shapefile.FieldType.N:
|
|
238
|
+
nan_description = NanCategorical_V1_0_1(values=[part.nan_def])
|
|
239
|
+
schema = pa.schema([("values", pa.int64())])
|
|
240
|
+
table = pa.table({"values": part.data}, schema=schema)
|
|
241
|
+
data_hash = self._create_parquet_file(table)
|
|
242
|
+
values = IntegerArray1_V1_0_1(data=data_hash, length=len(part.data), data_type="int64")
|
|
243
|
+
return IntegerAttribute_V1_1_0(
|
|
244
|
+
name=field_name,
|
|
245
|
+
key=data_hash,
|
|
246
|
+
attribute_description=None,
|
|
247
|
+
nan_description=nan_description,
|
|
248
|
+
values=values,
|
|
249
|
+
)
|
|
250
|
+
case shapefile.FieldType.F:
|
|
251
|
+
nan_description = NanContinuous_V1_0_1(values=[part.nan_def])
|
|
252
|
+
schema = pa.schema([("values", pa.float64())])
|
|
253
|
+
table = pa.table({"values": part.data}, schema=schema)
|
|
254
|
+
data_hash = self._create_parquet_file(table)
|
|
255
|
+
values = FloatArray1_V1_0_1(data=data_hash, length=len(part.data), data_type="float64")
|
|
256
|
+
return ContinuousAttribute_V1_1_0(
|
|
257
|
+
name=field_name,
|
|
258
|
+
key=data_hash,
|
|
259
|
+
attribute_description=None,
|
|
260
|
+
nan_description=nan_description,
|
|
261
|
+
values=values,
|
|
262
|
+
)
|
|
263
|
+
case shapefile.FieldType.C | shapefile.FieldType.M:
|
|
264
|
+
schema = pa.schema([("values", pa.string())])
|
|
265
|
+
table = pa.table({"values": part.data}, schema=schema)
|
|
266
|
+
data_hash = self._create_parquet_file(table)
|
|
267
|
+
values = StringArray_V1_0_1(data=data_hash, length=len(part.data))
|
|
268
|
+
return StringAttribute_V1_1_0(name=field_name, key=data_hash, attribute_description=None, values=values)
|
|
269
|
+
case shapefile.FieldType.L:
|
|
270
|
+
schema = pa.schema([("values", pa.bool_())])
|
|
271
|
+
table = pa.table({"values": part.data}, schema=schema)
|
|
272
|
+
data_hash = self._create_parquet_file(table)
|
|
273
|
+
values = BoolArray1_V1_0_1(data=data_hash, length=len(part.data))
|
|
274
|
+
return BoolAttribute_V1_1_0(name=field_name, key=data_hash, attribute_description=None, values=values)
|
|
275
|
+
case shapefile.FieldType.D:
|
|
276
|
+
schema = pa.schema([("values", pa.timestamp("us", tz="UTC"))])
|
|
277
|
+
# pyshp provides dates as date objects so we must convert to datetimes. Time is set to 00:00:00.
|
|
278
|
+
table = pa.table({"values": part.data}, schema=schema)
|
|
279
|
+
nan_description = NanCategorical_V1_0_1(values=[part.nan_def])
|
|
280
|
+
data_hash = self._create_parquet_file(table)
|
|
281
|
+
values = DateTimeArray_V1_0_1(data=data_hash, length=len(part.data))
|
|
282
|
+
return DateTimeAttribute_V1_1_0(
|
|
283
|
+
name=field_name,
|
|
284
|
+
key=data_hash,
|
|
285
|
+
attribute_description=None,
|
|
286
|
+
nan_description=nan_description,
|
|
287
|
+
values=values,
|
|
288
|
+
)
|
|
289
|
+
case _:
|
|
290
|
+
return None
|
|
291
|
+
|
|
292
|
+
def _create_parquet_file(self, table: pa.table) -> str:
|
|
293
|
+
"""
|
|
294
|
+
Writes a parquet file from the given table using the data client.
|
|
295
|
+
|
|
296
|
+
:param table: The table to write.
|
|
297
|
+
|
|
298
|
+
:return: The file hash of the written table.
|
|
299
|
+
"""
|
|
300
|
+
saved_table_info = self.data_client.save_table(table)
|
|
301
|
+
return saved_table_info["data"]
|
evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/prj_parser.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright © 2026 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from evo.data_converters.common import InvalidCRSError, crs_from_any
|
|
13
|
+
from evo_schemas.components import Crs_V1_0_1
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def prj_to_crs(filepath: str | None) -> Crs_V1_0_1:
|
|
17
|
+
if filepath is None:
|
|
18
|
+
return crs_from_any(filepath)
|
|
19
|
+
|
|
20
|
+
with open(filepath) as reader:
|
|
21
|
+
crs_str = reader.read()
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
return crs_from_any(crs_str)
|
|
25
|
+
except InvalidCRSError:
|
|
26
|
+
return crs_from_any(None)
|
evo_data_converters_shp-0.1.0/src/evo/data_converters/shp/importer/implementation/shp_parser.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Copyright © 2026 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import shapefile
|
|
15
|
+
from evo.data_converters.shp.importer.exceptions import InvalidSHPError
|
|
16
|
+
from evo.data_converters.shp.importer.implementation.mesh_builder import MeshBuilder
|
|
17
|
+
from evo.objects.utils.data import ObjectDataClient
|
|
18
|
+
from evo_schemas.components import BoundingBox_V1_0_1, Crs_V1_0_1
|
|
19
|
+
from evo_schemas.objects.triangle_mesh import TriangleMesh_V2_2_0
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ShpParser:
|
|
23
|
+
"""
|
|
24
|
+
Converts multipatch shapefiles (consiting of at least .shp, .shx, and .dbf files) to Triangle Mesh format.
|
|
25
|
+
Currently only supports multipatch files without rings.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, path: str, data_client: ObjectDataClient, crs: Crs_V1_0_1, tags: dict[str, str] = None):
|
|
29
|
+
"""
|
|
30
|
+
Initialize the shapefile to triangle mesh converter.
|
|
31
|
+
|
|
32
|
+
:param path: The path to the input shapefile. Can be just the basename, a path to any component file, or
|
|
33
|
+
a path to a zip file containing the shapefile.
|
|
34
|
+
:param data_client: Object data client for uploading parquet files (real or stub).
|
|
35
|
+
:param crs: Coordiante reference system to use for the file. Cannot be None, but can be "unspecified".
|
|
36
|
+
:param tags: (Optional) Dict of tags to add to the Geoscience Object(s)."
|
|
37
|
+
"""
|
|
38
|
+
self.path = path
|
|
39
|
+
self.data_client = data_client
|
|
40
|
+
self.crs = crs
|
|
41
|
+
self.tags = tags
|
|
42
|
+
|
|
43
|
+
def parse_shp(self) -> TriangleMesh_V2_2_0:
|
|
44
|
+
"""
|
|
45
|
+
Open, validate, and parse the shapefile, converting and returning it as a Triangle Mesh.
|
|
46
|
+
|
|
47
|
+
:return: Triangle Mesh object representing the input shapefile.
|
|
48
|
+
|
|
49
|
+
:raise InvalidSHPError: If the input shapefile is invalid or cannot be parsed
|
|
50
|
+
"""
|
|
51
|
+
with shapefile.Reader(self.path) as sf:
|
|
52
|
+
if sf.shapeType != shapefile.MULTIPATCH:
|
|
53
|
+
raise InvalidSHPError(
|
|
54
|
+
"Provided shapefile is not multipatch. Only multipatch shapefiles without rings are supported."
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
mesh_builder = MeshBuilder(self.data_client, sf.fields[1:])
|
|
58
|
+
|
|
59
|
+
bounding_box = BoundingBox_V1_0_1(
|
|
60
|
+
min_x=sf.bbox[0],
|
|
61
|
+
min_y=sf.bbox[1],
|
|
62
|
+
min_z=sf.zbox[0] or 0.0,
|
|
63
|
+
max_x=sf.bbox[2],
|
|
64
|
+
max_y=sf.bbox[3],
|
|
65
|
+
max_z=sf.zbox[1] or 0.0,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
for shape_record in sf.iterShapeRecords():
|
|
69
|
+
mesh_builder.add_shape_record(shape_record)
|
|
70
|
+
|
|
71
|
+
embedded_mesh = mesh_builder.build()
|
|
72
|
+
|
|
73
|
+
return TriangleMesh_V2_2_0(
|
|
74
|
+
triangles=embedded_mesh.triangles,
|
|
75
|
+
parts=embedded_mesh.parts,
|
|
76
|
+
name=Path(self.path).stem,
|
|
77
|
+
uuid=None,
|
|
78
|
+
tags=self.tags,
|
|
79
|
+
bounding_box=bounding_box,
|
|
80
|
+
coordinate_reference_system=self.crs,
|
|
81
|
+
)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Copyright © 2026 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
import pyarrow as pa
|
|
13
|
+
from evo.objects.utils.data import ObjectDataClient
|
|
14
|
+
from evo_schemas.components import (
|
|
15
|
+
ContinuousAttribute_V1_1_0,
|
|
16
|
+
NanContinuous_V1_0_1,
|
|
17
|
+
Triangles_V1_2_0,
|
|
18
|
+
Triangles_V1_2_0_Indices,
|
|
19
|
+
Triangles_V1_2_0_Vertices,
|
|
20
|
+
)
|
|
21
|
+
from evo_schemas.elements import (
|
|
22
|
+
FloatArray1_V1_0_1,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TrianglesBuilder:
|
|
27
|
+
"""
|
|
28
|
+
Builds a Triangles geoscience object from lists of triangles and their data.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
class _Vertex_Data:
|
|
32
|
+
"""Stores the data and index in the vertices array of this vertex."""
|
|
33
|
+
|
|
34
|
+
def __init__(self, index: int, data: float):
|
|
35
|
+
self.index = index
|
|
36
|
+
self.data = data
|
|
37
|
+
|
|
38
|
+
def __init__(self, data_client: ObjectDataClient):
|
|
39
|
+
"""
|
|
40
|
+
Initializes the Triangles builder.
|
|
41
|
+
|
|
42
|
+
:param data_client: Object data client for uploading parquet files (real or stub).
|
|
43
|
+
"""
|
|
44
|
+
self.vertices = {}
|
|
45
|
+
self.triangles = []
|
|
46
|
+
self.data_client = data_client
|
|
47
|
+
|
|
48
|
+
def add_triangle(self, triangle_vertices: list[tuple[float, float, float]], vertex_data: list[float | None]):
|
|
49
|
+
"""
|
|
50
|
+
Adds a triangle and it's vertex data to the builder.
|
|
51
|
+
|
|
52
|
+
:param triangle_vertices: The (x, y, z) formatted vertices of the triangle. len(triangle_vertices) == 3.
|
|
53
|
+
:param vertex_data: The data for each vertex (Data values can be None). len(vertex_data) == len(triangle_vertices)
|
|
54
|
+
"""
|
|
55
|
+
assert len(triangle_vertices) == len(vertex_data), "Not all vertices have data."
|
|
56
|
+
|
|
57
|
+
triangle = []
|
|
58
|
+
for i in range(len(triangle_vertices)):
|
|
59
|
+
index = self._add_or_get_vertex(triangle_vertices[i], vertex_data[i]).index
|
|
60
|
+
triangle.append(index)
|
|
61
|
+
self.triangles.append(tuple(triangle))
|
|
62
|
+
|
|
63
|
+
def get_num_triangles(self) -> int:
|
|
64
|
+
"""Get the number of triangles added to the builder so far."""
|
|
65
|
+
return int(len(self.triangles) / 3)
|
|
66
|
+
|
|
67
|
+
def build(self) -> Triangles_V1_2_0:
|
|
68
|
+
"""
|
|
69
|
+
Builds a Triangles geoscience object from the triangles added so far.
|
|
70
|
+
"""
|
|
71
|
+
n0, n1, n2 = zip(*self.triangles)
|
|
72
|
+
schema = pa.schema([("n0", pa.uint64()), ("n1", pa.uint64()), ("n2", pa.uint64())])
|
|
73
|
+
table = pa.table({"n0": n0, "n1": n1, "n2": n2}, schema=schema)
|
|
74
|
+
triangle_hash = self._create_parquet_file(table)
|
|
75
|
+
indices = Triangles_V1_2_0_Indices(
|
|
76
|
+
attributes=None, data=triangle_hash, length=len(self.triangles), data_type="uint64"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
x = []
|
|
80
|
+
y = []
|
|
81
|
+
z = []
|
|
82
|
+
vertex_data_list = []
|
|
83
|
+
vertex_nan = float("nan")
|
|
84
|
+
has_vertex_data = False
|
|
85
|
+
for vertex, vertex_data in self.vertices.items():
|
|
86
|
+
x.append(vertex[0])
|
|
87
|
+
y.append(vertex[1])
|
|
88
|
+
z.append(vertex[2])
|
|
89
|
+
if vertex_data.data is not None:
|
|
90
|
+
vertex_data_list.append(vertex_data.data)
|
|
91
|
+
has_vertex_data = True
|
|
92
|
+
else:
|
|
93
|
+
vertex_data_list.append(vertex_nan)
|
|
94
|
+
|
|
95
|
+
schema = pa.schema([("x", pa.float64()), ("y", pa.float64()), ("z", pa.float64())])
|
|
96
|
+
table = pa.table({"x": x, "y": y, "z": z}, schema=schema)
|
|
97
|
+
vertex_hash = self._create_parquet_file(table)
|
|
98
|
+
|
|
99
|
+
vertex_attributes = None
|
|
100
|
+
|
|
101
|
+
if has_vertex_data:
|
|
102
|
+
schema = pa.schema([("values", pa.float64())])
|
|
103
|
+
table = pa.table({"values": vertex_data_list})
|
|
104
|
+
vertex_data_hash = self._create_parquet_file(table)
|
|
105
|
+
vertex_array = FloatArray1_V1_0_1(data=vertex_data_hash, length=len(vertex_data_list), data_type="float64")
|
|
106
|
+
vertex_nan_continuous = NanContinuous_V1_0_1(values=[vertex_nan])
|
|
107
|
+
vertex_attributes = [
|
|
108
|
+
ContinuousAttribute_V1_1_0(
|
|
109
|
+
name="Measurements",
|
|
110
|
+
key=vertex_data_hash,
|
|
111
|
+
attribute_description=None,
|
|
112
|
+
nan_description=vertex_nan_continuous,
|
|
113
|
+
values=vertex_array,
|
|
114
|
+
)
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
vertices = Triangles_V1_2_0_Vertices(
|
|
118
|
+
attributes=vertex_attributes, data=vertex_hash, length=len(self.vertices), data_type="float64"
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
triangle = Triangles_V1_2_0(vertices=vertices, indices=indices)
|
|
122
|
+
return triangle
|
|
123
|
+
|
|
124
|
+
def _add_or_get_vertex(self, vertex: tuple[float, float, float], m: float = None) -> _Vertex_Data:
|
|
125
|
+
"""
|
|
126
|
+
Returns the data in the vertices array for the requested vertex, adding it if it doesn't already exist.
|
|
127
|
+
|
|
128
|
+
:param vertex: The vertex to find or add. Only one instance of each vertex will ever be in the vertices list.
|
|
129
|
+
:param m: The data for this vertex. If the vertex already exists, it's value is not updated. A vertex is always
|
|
130
|
+
assumed to have the same value.
|
|
131
|
+
|
|
132
|
+
:return: The vertex data (including it's index in the vertices array).
|
|
133
|
+
"""
|
|
134
|
+
if vertex not in self.vertices:
|
|
135
|
+
length = len(self.vertices)
|
|
136
|
+
self.vertices[vertex] = self._Vertex_Data(length, m)
|
|
137
|
+
return self.vertices[vertex]
|
|
138
|
+
|
|
139
|
+
def _create_parquet_file(self, table: pa.table) -> str:
|
|
140
|
+
"""
|
|
141
|
+
Writes a parquet file from the given table using the data client.
|
|
142
|
+
|
|
143
|
+
:param table: The table to write.
|
|
144
|
+
|
|
145
|
+
:return: The file hash of the written table.
|
|
146
|
+
"""
|
|
147
|
+
saved_table_info = self.data_client.save_table(table)
|
|
148
|
+
return saved_table_info["data"]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Copyright © 2026 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
|
|
12
|
+
from datetime import date, datetime, timedelta
|
|
13
|
+
|
|
14
|
+
_EPOCH = datetime(1970, 1, 1)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def datetime_to_evo_timestamp(dt: datetime) -> int | None:
|
|
18
|
+
if dt is None:
|
|
19
|
+
return None
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
ts = dt.timestamp() * 1_000_000
|
|
23
|
+
except OSError:
|
|
24
|
+
# Occurs if the date is 1970/1/1 or earlier.
|
|
25
|
+
td = dt - _EPOCH
|
|
26
|
+
ts = td / timedelta(microseconds=1)
|
|
27
|
+
return int(ts)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def date_to_evo_timestamp(d: date) -> int | None:
|
|
31
|
+
if d is None:
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
return datetime_to_evo_timestamp(datetime(d.year, d.month, d.day))
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Copyright © 2026 Bentley Systems, Incorporated
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
8
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
# See the License for the specific language governing permissions and
|
|
10
|
+
# limitations under the License.
|
|
11
|
+
import os
|
|
12
|
+
from typing import TYPE_CHECKING, Optional
|
|
13
|
+
|
|
14
|
+
from evo.data_converters.common import (
|
|
15
|
+
EvoWorkspaceMetadata,
|
|
16
|
+
create_evo_object_service_and_data_client,
|
|
17
|
+
publish_geoscience_objects_sync,
|
|
18
|
+
)
|
|
19
|
+
from evo.data_converters.shp.importer.implementation.local_data import LocalDataClient
|
|
20
|
+
from evo.data_converters.shp.importer.implementation.prj_parser import prj_to_crs
|
|
21
|
+
from evo.data_converters.shp.importer.implementation.shp_parser import ShpParser
|
|
22
|
+
from evo.objects.data import ObjectMetadata
|
|
23
|
+
from evo_schemas.objects.triangle_mesh import TriangleMesh_V2_2_0
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from evo.notebooks import ServiceManagerWidget
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def convert_shp(
|
|
30
|
+
filepath: str,
|
|
31
|
+
filepath_prj: Optional[str] = None,
|
|
32
|
+
evo_workspace_metadata: Optional[EvoWorkspaceMetadata] = None,
|
|
33
|
+
service_manager_widget: Optional["ServiceManagerWidget"] = None,
|
|
34
|
+
tags: Optional[dict[str, str]] = None,
|
|
35
|
+
upload_path: str = "",
|
|
36
|
+
publish_objects: bool = True,
|
|
37
|
+
overwrite_existing_objects: bool = False,
|
|
38
|
+
) -> list[TriangleMesh_V2_2_0] | list[ObjectMetadata]:
|
|
39
|
+
"""
|
|
40
|
+
Convert an ESRI shapefile (.shp, .shx, and .dbf) to a triangle-mesh geoscience object.
|
|
41
|
+
|
|
42
|
+
:param filepath: Path to the base filename of the shapefile, any of the component files (.shp, .shx, or .dbf),
|
|
43
|
+
or a zip file containing the shapefile.
|
|
44
|
+
:param epsg_code: The EPSG code to use when creating a Coordinate Reference System object.
|
|
45
|
+
:param evo_workspace_metadata: (Optional) Evo workspace metadata.
|
|
46
|
+
:param service_manager_widget: (Optional) Service Manager Widget for use in jupyter notebooks.
|
|
47
|
+
:param tags: (Optional) Dict of tags to add to the Geoscience Object(s).
|
|
48
|
+
:param upload_path: (Optional) Path objects will be published under.
|
|
49
|
+
:param publish_objects: (Optional) Set False to prevent publishing and instead return Geoscience models.
|
|
50
|
+
:param overwrite_existing_objects: (Optional) Set True to overwrite any existing object at the destiation path.
|
|
51
|
+
|
|
52
|
+
:return: list[ObjectMetadata] if publish_objects is true, otherwise list[Regular2DGrid]
|
|
53
|
+
|
|
54
|
+
:raise MissingConnectionDetailsError: If no connections details could be derived.
|
|
55
|
+
:raise ConflictingConnectionDetailsError: If both evo_workspace_metadata and service_manager_widget present.
|
|
56
|
+
:raise InvalidOBJError: If the input shapefile is invalid or cannot be parsed.
|
|
57
|
+
:raise InvalidCRSError: If the input CRS information is invalid.
|
|
58
|
+
|
|
59
|
+
One of evo_workspace_metadata or service_manager_widget is required for publishing.
|
|
60
|
+
"""
|
|
61
|
+
geoscience_objects = []
|
|
62
|
+
|
|
63
|
+
if publish_objects:
|
|
64
|
+
object_service_client, data_client = create_evo_object_service_and_data_client(
|
|
65
|
+
evo_workspace_metadata=evo_workspace_metadata, service_manager_widget=service_manager_widget
|
|
66
|
+
)
|
|
67
|
+
else:
|
|
68
|
+
data_client = LocalDataClient(upload_path)
|
|
69
|
+
|
|
70
|
+
full_tags = {
|
|
71
|
+
"Source": f"{os.path.basename(filepath)} (via Evo Data Converters)",
|
|
72
|
+
"Stage": "Experimental",
|
|
73
|
+
"InputType": "SHP",
|
|
74
|
+
**(tags or {}),
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
crs = prj_to_crs(filepath_prj)
|
|
78
|
+
|
|
79
|
+
parser = ShpParser(path=filepath, data_client=data_client, crs=crs, tags=full_tags)
|
|
80
|
+
mesh = parser.parse_shp()
|
|
81
|
+
|
|
82
|
+
geoscience_objects.append(mesh)
|
|
83
|
+
|
|
84
|
+
objects_metadata = None
|
|
85
|
+
if publish_objects:
|
|
86
|
+
print("Publishing Shapefile")
|
|
87
|
+
objects_metadata = publish_geoscience_objects_sync(
|
|
88
|
+
geoscience_objects, object_service_client, data_client, upload_path, overwrite_existing_objects
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return objects_metadata if objects_metadata else geoscience_objects
|