JuliaEarth / GeoIO.jl

Load/save geospatial data compatible with the GeoStats.jl framework
https://github.com/JuliaEarth/GeoStats.jl
MIT License
21 stars 5 forks source link

Add `lenunit` option to `GeoIO.load` #100

Open kramsretlow opened 1 month ago

kramsretlow commented 1 month ago

I have an .obj file that was exported from a CAD program. The CAD software was using mm as the unit. If I import it as a SimpleMesh using GeoIO.load(filename).geometry, it comes out with units of meters. Is it (or could it be) possible to specify the units in the call to load? And/or, is there an easy way to change the units of a mesh after creation? Right now I am using the inelegant way of loading the mesh, then creating a new mesh with a fix_part_units function defined like this:

fix_unit(p) = Meshes.Point((ustrip.([coords(p).x, coords(p).y, coords(p).z]) .* u"mm")...)
fix_part_units(msh) = SimpleMesh([fix_unit(v) for v in vertices(msh)], msh.topology)

I've tried searching the docs and source, but I can't find the functionalities I'm after. Sorry if I've missed something.

I'm not familiar with all of the file formats, but I guess this point could apply to some other "unitless" formats as well.

juliohm commented 1 month ago

Hi @kramsretlow, it is good to see you.

We should probably add a lengthunit option to load as suggested given that .obj files don't store units.

Would you like to try adding the option yourself? You can forward it to any affected format, and we can review it.

kramsretlow commented 1 month ago

Hi @juliohm , thanks for remembering me 😄

I will try to make some time in the next while to work on it, though I can't promise it'll get done. So far I was still unable to find the point in the source where the meters unit magically joined my mesh coordinates--will need to check it more deeply.

I'm really enjoying using Meshes.jl for some computation job I'm doing on 3D parts. If one comes to Meshes.jl from a direction not related to geographical data, it feels slightly odd to need to go to GeoIO.jl (which is clearly geostats related) to load a mesh. Not a problem, but just a comment from user's perspective. In any case, thanks for your work on these packages!

juliohm commented 1 month ago

I was still unable to find the point in the source where the meters unit magically joined my mesh coordinates--will need to check it more deeply.

The units are added in the Point constructor. You can write Point(x, y) with x and y unitful quantities:

Point(1mm, 2mm)

m is the default unit when x and y are not unitful.

You can add a unit to a pre-existing tuple with:

u = mm

Point(x * u, y * u)

I'm really enjoying using Meshes.jl for some computation job I'm doing on 3D parts.

Glad you are enjoying it :)

If one comes to Meshes.jl from a direction not related to geographical data, it feels slightly odd to need to go to GeoIO.jl (which is clearly geostats related) to load a mesh. Not a problem, but just a comment from user's perspective. In any case, thanks for your work on these packages!

GeoIO.jl is not tied to GeoStats.jl (the package), but is certainly related to GeoStats.jl (the framework). It doesn't depend on the "stats" part of "geostats". Think of it as a simple tool to load geospatial data as geotables, which can be used for any purpose beyond geospatial data science and geostatistical modeling.

juliohm commented 1 month ago

@kramsretlow the option should be available now. Please update the environment.

I will leave the issue open because there some other formats also support the option, but we didn't have time to implement yet:

juliohm commented 2 days ago

/bounty $20

algora-pbc[bot] commented 2 days ago

💎 $20 bounty • JuliaEarth

Steps to solve:

  1. Start working: Comment /attempt #100 with your implementation plan
  2. Submit work: Create a pull request including /claim #100 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to JuliaEarth/GeoIO.jl!

Add a bounty • Share on socials

Attempt Started (GMT+0) Solution
🟢 @mobley-trent Sep 10, 2024, 6:11:33 AM WIP
mobley-trent commented 2 days ago

/attempt #100

Algora profile Completed bounties Tech Active attempts Options
@mobley-trent 10 bounties from 5 projects
Python, Rust,
Jupyter Notebook
Cancel attempt
mobley-trent commented 2 days ago

Hello @juliohm correct me if I'm wrong but this issue seems to have been fixed in #110

juliohm commented 1 day ago

@mobley-trent it is partially fixed. The option is not available in the formats listed above in a check list.

mobley-trent commented 1 day ago

I see that vtkread, imgread and csvread are referenced in the load function. Perhaps I am missing something @juliohm ?

juliohm commented 1 day ago

The option is passed to the inner functions, but it is being currently ignored. See the csvread for example:

https://github.com/JuliaEarth/GeoIO.jl/blob/8201229c6987924fb73ab49b3753b037d2ee1203/src/extra/csv.jl#L5

The option is not used inside the function.