tmontaigu / shapefile-rs Goto Github PK
View Code? Open in Web Editor NEWRust library to read & write shapefiles
License: MIT License
Rust library to read & write shapefiles
License: MIT License
Hi, thank you for this project ๐
I'm using your project to create shapefiles and it seems that indexes are corrupted, I can't open the result shapefile with QGIS.
My test is this one :
use shapefile::record::poly::GenericPolygon;
use shapefile::*;
#[test]
pub fn test() {
let poly: GenericPolygon<Point> = GenericPolygon::new(vec![
Point::new(-2.109375, 54.57206165565852),
Point::new(-11.953125, 31.952162238024975),
Point::new(31.640625, 44.08758502824516),
Point::new(-2.109375, 54.57206165565852),
]);
Writer::from_path("/tmp/shp/test.shp")
.unwrap()
.write_shapes(vec![poly])
.unwrap();
}
The test as GeoJSON :
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[ -2.109375, 54.57206165565852 ],
[ -11.953125, 31.952162238024975 ],
[ 31.640625, 44.08758502824516 ],
[ -2.109375, 54.57206165565852 ]
]
]
}
}
I used Qgis to transform the GeoJSON to a shapefile. I found that the QGIS index and Shapefile-rs index where different.
I did a hexyl (the rust version of hexdump) and here is the result :
hexyl shapefile-rs.shx
โโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโ
โ00000000โ 00 00 27 0a 00 00 00 00 โ 00 00 00 00 00 00 00 00 โ00'_0000โ00000000โ
โ00000010โ 00 00 00 00 00 00 00 00 โ 00 00 00 36 e8 03 00 00 โ00000000โ0006รโข00โ
โ00000020โ 05 00 00 00 00 00 00 00 โ 00 e8 27 c0 ae cd 88 e7 โโข0000000โ0ร'รรรรรโ
โ00000030โ c0 f3 3f 40 00 00 00 00 โ 00 a4 3f 40 ab 2c fb 50 โรร?@0000โ0ร?@ร,รPโ
โ00000040โ 39 49 4b 40 00 00 00 00 โ 00 00 00 00 00 00 00 00 โ9IK@0000โ00000000โ
โ00000050โ 00 00 00 00 00 00 00 00 โ 00 00 00 00 00 00 00 00 โ00000000โ00000000โ
โ00000060โ 00 00 00 00 00 00 00 64 โ 00 00 00 38 โ0000000dโ0008 โ
โโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโ
hexyl qgis.shx
โโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโ
โ00000000โ 00 00 27 0a 00 00 00 00 โ 00 00 00 00 00 00 00 00 โ00'_0000โ00000000โ
โ00000010โ 00 00 00 00 00 00 00 00 โ 00 00 00 36 e8 03 00 00 โ00000000โ0006รโข00โ
โ00000020โ 05 00 00 00 00 00 00 00 โ 00 e8 27 c0 ae cd 88 e7 โโข0000000โ0ร'รรรรรโ
โ00000030โ c0 f3 3f 40 00 00 00 00 โ 00 a4 3f 40 ab 2c fb 50 โรร?@0000โ0ร?@ร,รPโ
โ00000040โ 39 49 4b 40 00 00 00 00 โ 00 00 00 00 00 00 00 00 โ9IK@0000โ00000000โ
โ00000050โ 00 00 00 00 00 00 00 00 โ 00 00 00 00 00 00 00 00 โ00000000โ00000000โ
โ00000060โ 00 00 00 00 00 00 00 32 โ 00 00 00 38 โ00000002โ0008 โ
โโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโ
The first 100 bytes are correct (the index header) but the 8 last bytes are different, we see 64 with this project and 32 with qgis.
When I replace shapefile-rs.shx by qgis.shx it works like a charm, tha'ts why I think the issue is in the index.
There is a problem that can't parse chinese char in the *.dbf file just like the above show , can you fix it ?the result like Character(Some("๏ฟฝุฟ๏ฟฝาป"))
Sent with GitHawk
Current constructors for the shapes are error-prone
The current form new(points: Vec<PointType>, parts: Vec<i32>)
requires that users properly organize the points in the Vec and that parts array is properly populated.
As no real checks are done, this can lead to wrong shapefile being written.
We should change constructors to something like:
new(points: Vec<PointType>)
with_multiparts(points: Vec<Vec<PointType>>)
Constructor could then sort points clock-wise/counter clock-wise to match the ESRI standard
and generate the parts array preventing from mistakes.
And maybe we could add Builders.
I don't see how I can get the CRS out of a shapefile read with this library. Am I correct that these are the docs for this project? If so, I don't see "CRS" mentioned in there. Should I be using another library?
This might not be possible as some geotypes are not compatible / has no shapefile equivalent, but should still be looked into
Hey,
Thanks for the great parsing but i would like to convert your object to geotype.
I try with try_into but doesn't work. Have you any idea on how to do this ?
Hi,
I was trying to see if I could get this crate to work with the newest version of another one of your crates, dbase
0.1.
Although the API has changed I think I was able to figure out how to switch from a dbase::Writer
to a dbase::TableWriter
.
Unfortunately, I seem to be stuck dealing with some ownership issues - since dbase::Reader
isn't Iterator
anymore, I had to rewrite iter_shapes_and_records_as to return a dbase::RecordIterator
, but I can't figure out how to give something ownership of the dbase::Reader
I wrote my function something like this.
pub fn iter_shapes_and_records_as<'a, S: ReadableShape>(
mut self,
) -> Result<ShapeRecordIterator<'a, T, S>, Error> {
let mut dbf_reader = self.dbf_reader.take().ok_or(Error::MissingDbf)?; // Now dbf_reader is owned by the current function
let dbf_iter = dbf_reader.iter_records(); // but a dbase::RecordIterator only has a reference to it: `&'a mut Reader<T>`
Ok(ShapeRecordIterator{
shape_iter: self.iter_shapes_as::<S>(),
dbf_iter, // thus this is invalid because it "returns a value referencing data owned by the current function"
})
}
Sorry if this issue was invalid but I can't figure out of this is an issue with dbase
, or if I'm just not writing something correctly.
read shapefile can be assign "utf-8","gbk" for better read charactor code
Shape: Shape::Polyline(1 parts), records:
former_nam: Character(None),
Route_ID: Character(Some("99564")),
Path_Name: Character(Some("๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ")),
The changes for allowing multiple versions of geo-types
look great, thanks for maintaining this! Would it be possible to publish a new release with those updates?
Hello,
I am a beginner in rust and shape file in general.
When i open shape, shapefile panic :
'main' panicked at 'attempt to multiply with overflow', ...shapefile-0.3.0\src\reader.rs:107:23.
My code (simplify) :
fn open_shape(filename: String) -> Vec<(shapefile::Shape, dbase::Record)>{
let mut reader;
match shapefile::Reader::from_path(filename.to_string()){
Ok(x) => reader = x,
Err(shapefile::Error::MissingDbf) => exit(2),
_ => exit(3)
};
match reader.read() {
Ok(data_shape) => return data_shape,
Err(e) => exit(4)
}
}
When i debug i see this :
panic in reader.read() in read_one_shape_as
this line : reader.rs 107 : let record_size = hdr.record_size * 2;
hdr.record_size = -1409209791
I don't if my shape have a problem or if it's an error not properly catch by the library.
i have no problem to open my shape in qgis
I'm very new to Rust (somewhat experienced with GIS but it's not my main background), so apologies if there's something I just failed to grok properly.
I'm trying to read shapefiles with contour lines (from the Ordanance Survey Terr50 data FWIW), which are grouped into features with 2d coordinates and a 'PROP_VALUE'
indicating the height of each line. I've previously been using https://github.com/calvinmetcalf/shapefile-js and wanted to experiment with porting that code to Rust / WASM.
In the context of shapefile.js
, they parse the results into GeoJSON FeatureCollection
, where each Feature
has, in addition to geometry, a set of arbitrary properties indexed by string. So I access the height with feature.properties['PROP_VALUE']
.
Reading through your documentation and code, I don't think I see anyway to do the equivalent with shapefile-rs, so I guess it's just a missing feature, but I could well have missed something.
it don't make any sense
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.