andelf / rust-postgis Goto Github PK
View Code? Open in Web Editor NEWpostgis helper library.
License: MIT License
postgis helper library.
License: MIT License
It would be very helpful to see a more complete example of how to use this. Especially on how to use this when writing geo data. I would happily do a PR, but unfortunately I don't understand enough about this library to contribute that at this point.
I'm currently making a rest API that needs to take the cords to construct a bounding box for a query. It would be great if rust-postgis had types for Box2d and Box3d. This would allow me to do things like..
SELECT *
FROM table
WHERE $1 && table.geog;
SELECT *
FROM table
WHERE ST_Intersects($1, table.geog);
I get this exception for MultiLineString (and also MultiPolygon) when reading any data in EPSG:3857.
println!(">>>>>> {:#?}", row.get::<_, postgis::MultiLineString<postgis::Point<EPSG_3857>>>("wkb_geometry"));
->
thread 'datasource::postgis::test_from_geom_fields' panicked at 'called "Result::unwrap()" on an "Err" value: Read("error while reading: UnexpectedEOF")', ../src/libcore/result.rs:688
Here's a failing MultiLineString:
'0105000020110F000001000000010200000004000000A149950DA3BB564189DF62973DC35C4165CD9E8413C6564189DF62973DC35C410C6A639A84C856413CC52F806BC25C4159E55A3637CD5641D6FD917DC6BE5C41'::geometry
SRID=3857;MULTILINESTRING((5959308.21223679 7539958.36540974,5969998.07219252 7539958.36540974,5972498.41231776 7539118.00291568,5977308.84929784 7535385.96203562))
Greetings,
What are your thoughts on a possible feature-flag (or just straight use) that supports the crate https://github.com/georust/rust-geo for the rust-postgis extension?
In general, I like the design of the https://github.com/georust projects, because they use a single crate which defines the base geometric types and then have other projects to convert between specific formats (eg. https://github.com/georust/rust-geojson, https://github.com/georust/rust-wkt).
It's wrong using unsafe { *mem::transmute::<_, *const f64>(self) }
https://doc.rust-lang.org/reference/type-layout.html#the-default-representation
There are no guarantees of data layout made by this representation.
Why not just self.x, self.y and so ones
Hi. Just wanted to ask - is there a way to get the geometry if the postgis geometry is a curve (such as CURVEPOLYGON
and CIRCULARSTRING
, etc.)?
It would be nice if the From<(tuple)> trait was implemented for the Point types. the corresponding types in geo_types implement this trait and it makes it easier to create these types with iterators and the like.
Please add optional support for serde's Serialize/Deserialize traits.
Like this:
serde = { version = "1.0", features = ["derive"], optional = true }
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Point { // postgis::ewkb::Point
Thanks!
I was attempting to integrate this library with diesel while using the nightly compiler.
Do you know off the top of your head problem changes in nightly that would cause build failures? It is fine if you don't know. I can debug it myself but I wanted to check for any possible leads from the people who know the most about this library first. Please tell me if you don't know so I can begin working on the problem.
All of the errors look like the blanket trait implementations not being found by the compiler. If you know the name of the problem or the rust issue the this comes from that would be a huge help.
error[E0277]: the trait bound `usize: types::MultiPolygon<'a>` is not satisfied
--> src/postgis.rs:138:13
|
138 | / fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
139 | | self.write_ewkb(out)?;
140 | | Ok(IsNull::No)
141 | | }
| |_____________^ the trait `types::MultiPolygon<'a>` is not implemented for `usize`
...
150 | impl_sql_for_ewkb_type!(multipoly EwkbMultiPolygon contains Polygon);
| --------------------------------------------------------------------- in this macro invocation
error[E0277]: the trait bound `usize: types::MultiPolygon<'a>` is not satisfied
--> src/postgis.rs:150:1
|
150 | impl_sql_for_ewkb_type!(multipoly EwkbMultiPolygon contains Polygon);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the trait `types::MultiPolygon<'a>` is not implemented for `usize`
| in this macro invocation
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 128 previous errors
For more information about this error, try `rustc --explain E0277`.
error: Could not compile `postgis`
I can't find a way to select geometries without specifying the SRID at compile time. Is there a way to read the SRID from geometry_columns at runtime and select geometries using this SRID?
I'm using diesel and Postgres+PostGIS. In my table I'm using loc geography(point, 4326) not null
, in my table!{}
schema loc -> Point
(postgis::ewkb::Point
) and in my ORM struct loc: MyPoint
.
Then I have:
use postgis::ewkb::Point;
#[derive(Debug, Clone, PartialEq, FromSqlRow, AsExpression)]
pub struct MyPoint(Point); // newtype
impl FromSql<Point, Pg> for MyPoint {
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
use std::io::Cursor;
use postgis::ewkb::EwkbRead;
let bytes = not_none!(bytes);
let mut rdr = Cursor::new(bytes);
Ok(MyPoint(Point::read_ewkb(&mut rdr)?))
}
}
impl ToSql<Point, Pg> for MyPoint {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
use postgis::ewkb::{AsEwkbPoint, EwkbWrite};
self.0.as_ewkb().write_ewkb(out)?;
Ok(IsNull::No)
}
}
But when I try to use it in a diesel query (such as users.load::<models::User>(conn)
) I get:
error: src\main.rs:56: the trait bound
diesel::pg::Pg: diesel::sql_types::HasSqlType<postgis::ewkb::Point>
is not satisfied
note: src\main.rs:56: required because of the requirements on the impl ofdiesel::sql_types::HasSqlType<(diesel::sql_types::BigInt, postgis::ewkb::Point, diesel::sql_types::Float)>
fordiesel::pg::Pg
note: src\main.rs:56: required because of the requirements on the impl ofdiesel::query_dsl::LoadQuery<r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>, models::User>
forschema::users::table
According to the docs I should #[derive(SqlType)]
on Point
(or MyPoint
) but what are the oid
and array_oid
for geography(point, 4326)
?
Please derive Copy
for the point types like postgis::ewkb::Point
.
It would be nice if Default
was implemented for Point
. Without it migration from geo_types
is that much harder. Moreover, we can't use crates like derive-builder
which require Default.
The obvious choice for postgis::ewkb::Point
is (0,0)
with an SRID of None
The example doesn't work anymore (it worked a few weeks ago). It seems that the 0.4.0 version is missing the FromSQL trait for basically any type.
I just get errors a la:
the trait "graphics::renderer::postgres::types::FromSql" is not implemented for "types::osm_tuple::postgis::ewkb::Point"
I noticed that the 0.3.0 version had postgres::FromSql implemented: https://docs.rs/postgis/0.3.0/postgis/ewkb/struct.Point.html
The 0.4.0 has it too, but there seems to be something wrong - the trait isn't marked violet, as usual: https://docs.rs/postgis/0.4.0/postgis/ewkb/struct.Point.html
Plus, well, the examples as well as any code that worked with 0.3.0, doesn't compile anymore. It is impossible to get any geometry types out of a postgres database without this trait being implemented.
after merge #2 , breaks.
Would it make sense to migrate all internal postgis types to the proposed geo-types that support T, Z, and M generic types? Are there any changes that should be made to that proposal? How should SRID be added to it? One option might be to double the number of types - e.g. LineString
, LineStringM
, LineStringZ
, LineStringZM
, LineStringS
, LineStringMS
, LineStringZS
, LineStringZMS
, where all of them are aliases to pub struct LineStringTZM<T: CoordNum, Z: ZCoord, M: Measure, S: SRID>(...)
-- where SRID could be defined as either i32 or NoValue.
If SRID is not accepted to geo/geo-types as an i32 (which seems to be a postgis convention only), one option would be to have some sort of a wrapper enum as described in georust/wkt#91 with an additional i32 srid.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.