Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTableAccessor: Inserting geometry values into tables #34

Open
AL89 opened this issue Apr 18, 2024 · 3 comments
Open

DataTableAccessor: Inserting geometry values into tables #34

AL89 opened this issue Apr 18, 2024 · 3 comments
Assignees

Comments

@AL89
Copy link

AL89 commented Apr 18, 2024

Hi

I like the idea of this library to access certain things of the M+ database. And furthermore to insert data into it.

However, I was wondering how you insert spatial data into the M+ database for the data tables that contains geometric features, e.g. msm_Node, msm_Catchment, msm_Link etc.? How do you link the coordinates the each individual feature?

From the example that comes from the DataTableAccessor notebook, I would like to add another field that contains the geometric values (i.e. coordinates for upstream and downstream nodes). I mean, which format do I write this in? Should I convert it to shapely.geom objects, a WKT/WKB string, or what?

from mikeplus import DataTableAccess
data_access = DataTableAccess("../tests/testdata/Db/Sirius/Sirius.sqlite")
data_access.open_database()

values = {'Diameter': 2.0, 'Description': 'insertValues','geometry':LINESTRING(0 0, 1 1)} # <- added another field for 'geometry' with WKT geometry type
data_access.insert("msm_Link", "link_test", values)

Thanks in advance!

@ryan-kipawa
Copy link
Collaborator

Hi @AL89,

This is a really good point. I think there's two main things here:

  • 1. How are geometries represented in the MIKE+ database, and how can they currently be modified?
  • 2. How could this be improved through better integration with python packages like Shapely and GeoPandas?

Perhaps a startpoint is @wuwwen could answer 1 with:

  • Brief overview of the main geometry types used and how they're stored
  • Brief example of how to insert and modify geometries

@wuwwen
Copy link
Collaborator

wuwwen commented Oct 8, 2024

@ryan-kipawa, The insert method can't support insert geometry for the time being. But we can modify to support it. Both extension can be made for set_value method. But we need to define the input parameters. What data type should we support? Maybe it's WKT(Well know text)?

@ryan-kipawa
Copy link
Collaborator

ryan-kipawa commented Oct 8, 2024

@ryan-kipawa, The insert method can't support insert geometry for the time being. But we can modify to support it. Both extension can be made for set_value method. But we need to define the input parameters. What data type should we support? Maybe it's WKT(Well know text)?

It's very common in Python to use Shapely for geometries. Their objects can also be converted to WKT. I believe there's different versions and specifications of WKT, so we would need to make sure it works seamlessly with the format that MIKE+ accepts. I suggest:

  • 1. Try it the simplest way by accepting WKT. Clarify which version/format if WKT is required for compatibility with MIKE+.
  • 2. Explore if Shapely WKT is compatible with the above. If yes, then accept Shapely objects as the data structure in addition to WKT for convenience. If no, then try to document the main reason why so we can explore potential solutions.

@wuwwen wuwwen self-assigned this Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants