Skip to content
Loki The Great edited this page Apr 8, 2021 · 4 revisions

Introduction

So, I'm going to write this in language that won't put a developer asleep.

FOCUS

If you ever searched for shape file readers, you probably came up a tad bit disappointed. Since I've been writing and rewriting this project forever, I took the annoyance out of that search.

Ladies and gentleman allow me to introduce Loki The Great's shape file utilities library. (LOGSFUL) because we need an acronym !

It slices, it dices, its tears apart a shapefile and prepares it for MSSQL integration in a single command !

Seriously though, it works pretty well.

In my fruitless search for simple parsers I found myself wondering in what the 40 years this spec has been around (plus some now since they deleted a lot of time from history in America), "why in the name of oh so gentle f-g Jesus has no-one written a simple hierarchical parser ? I mean why am I finding these complicated projects that require more time to understand than just writing one's own f-g project ?"

The answer ?.... I don't know.

But here it is. All it really needs at this point to be version 1.0 is a testable application for all the more obscure data types like PointM and PolyLineShapeM etc, to make sure the data is being read correctly and a few more WKT() serialization tidbits. Oh and a way of detecting and configuring the the coordinate system / projection type from some secondary file, like the included xml files that are distributed by the USGS along with their projects. Why do the feds have to suck so much ? I just want to love and believe in them :(. Anyway.

And I would appreciate if people would stop wasting my time in Fort Collins as I should not be stuck around said garbage here and the inhumanity at work in this place would cause Hitler's jaw to drop. I'm sick of having to rewrite my own goddamn code. These people seem to believe, like some kind of strange self deprecative cult, that rolling back time over and over by erasing records and works is somehow beneficial to this day some of these idiots will respond with the same brainwashed kneejerk response online and in person getting all strange and bat-eyed thinking they're getting away with murder, which they are, their own, hopefully.

Use

I made this pretty simple.

  1. Download the source, add it to an VS solution.

  2. In the implementing source include a

using ShapeUtilities;

Line at the beginning.

  1. Then in whatever function simply use:

Shapefile ashape = new ShapeFile("someshapefile.shp"); ashape.Load();

  1. Finally traverse the Records property or ashape.

foreach (RecordHeader brr in ashape.Records) { // some code here }

All shape types are derived from BaseShapeRecord, which is included in the RecordHeader class as property "Record".

Presently, so that the source implementations work with ado.net in general, there is a GetMSSQLInstance() method which will return a type which can be added to a **System.Data.DataTable **instance for SqlBulkCopy.

This is the fastest way of uploading the data to an instance of sql server.

Also the record GetExtent() will return a BoundingBox instance which indicates a rough containing box for use with comparisons.

Will add example code shortly. For a working example, check out my other work in progress which implements census and shapefile data sources to create the database backend for a working custom map system.

While I am contributing this code, I still like money, a donation link will be placed in these pages, please support my broke-ass efforts at reducing the time requirements to work with various public data sources and implement them into your respective projects.

Your pretty software can say "Oh thank you John R Sohn for investing large amounts of time therapizing yourself to my benefit, while remembering what the garbage in this section of our benighted and besieged country did to you when you were a boy because of your awful father who should be strung up by his testicles from a tree." Yeah, pretty much have no shame mentioning that since the feds haven't done this for me yet, and seem to ignore this f-ed up state altogether.

Remember kids a chomo dead is a child saved. Probably several saved in fact. This place really makes me miserable.

Shortcomings

This code is intended as a reader only. It is not yet implemented to write shapefiles, though this would be easy enough to add, just requiring a time investment.

As of now only a few shapes can be translated to Well Known Text (WKT).

Mainly PolyLineShape and PolygonShape as these are the only ones I have yet discovered in the ESRI shapefiles Uncle Sam distributes.

The MSSQL Instance I'm defaulting to 4326 for the projection type. Don't ask why I don't know. Point is I have been learning about GIS as I go and didn't realize there were differing projection types, so as of right now, conus albers nad83 is not simply going to be written, you'll have to update the code yourself for whatever projection system you use which really only amounts to changing one number in the BaseShapeRecord.GetMSSQLInstance() method.

Shouldn't be an issue with WKT. I'll add an update to this later.

Testing Status

Mainly I only use the most common shapes I have found in various shapefiles distributed by the United States federal government as part of its data publications. Not all shape types have been tested.

Further Reading

The ESRI documentation at www.esri.com,
you'll find a full specification that I have implemented here.

Clone this wiki locally