Exporting Longitude/Latitude vectors into a shapefile in Matlab
16 次查看(过去 30 天)
显示 更早的评论
Using Matlab I generate a vector with longitude data and one with latitude. I've read through this example in creating a polyline Geostruct and then exporting to a shapefile
My code is similar:
% create line geostruct
[Tracks(1:length(myLon)-1).Geometry] = deal('Line');
trackType = 'gc';
[Tracks.Type] = deal(trackType);
for i = 1:(length(myLon)-1)
[Tracks(i).Lon Tracks(i).Lat] = track2(trackType, myLon(i, 1), myLat(i, 1), myLon(i+1, 1), myLat(i+1, 1));
% write shapefile
shapewrite(Tracks, 'path_line');
end
I have a couple of questions: One is that I read that Geostruct doesn't include projections, but Mapstruct does. I don't see any examples of how to create a Mapstruct, however. So I would appreciate any instruction on how to do that. This is because I would like to project the line path on a map in ArcGIS.
Also, I considered writing a Point shapefile along with the line shapefile, but the shapewrite function does not output the .dbf file, only the .shx and .shp when I use Point. What could be the cause of this? My code for the Point Geostruct is here:
% create point geostruct
[Points(1:length(myLon)).Geometry] = deal('Point');
for i = 1:(length(myLon))
Points(i).Lon = myLon(i, 1);
Points(i).Lat = myLat(i, 1);
end
shapewrite(Points, 'path_point');
I would appreciate any help or direction in what I am trying to do. Thank you very much!
0 个评论
回答(1 个)
Rob Comer
2011-7-2
Question 1: Just to clarify a little -- a geostruct needs to have Lat and Lon fields in a geographic coordinate system. Their contents can be projected when displayed in a map axes via geoshow. A mapstruct needs to have X and Y fields that are already in a projected coordinate system.
Constructing a mapstruct from scratch is just like constructing a geostruct, except that you create the fields X and Y instead of Lat and Lon. Of course, the contents of X and Y have to be in the correct system. In your case, since you have them in a geographic system, you could create a map projection structure (an "mstruct", not to be confused with "mapstruct") -- see the doc on this -- and then apply the mfwdtran function to each line or point before adding it to your mapstruct.
The shapefile that you write from a mapstruct will thus be in your projected system, and if you're working in the same projected system in ArcGIS, you should be all set. I feel confident that you could also import a shapefile with geographic coordinates into ArcGIS and project it there, but that may require additional set-up or product capabilities. I can't speak from experience on this point.
Question 2: Your "Tracks" structure includes an attribute field (a field with a name other than Geometry, Lat, Lon, or BoundingBox); you called it Type. The contents of your attribute field(s) go into the .dbf file. But your "Points" structure has only the fields Geometry, Lat, and Lon. There are no attribute fields, so there's nothing to put into a .dbf file and shapewrite doesn't create one.
I don't know if ArcGIS requires a .dbf file (the shaperead function in Mapping Toolbox does not), but if it does, you can just add some arbitrary attribute field to Points before calling shapewrite.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!