I have many shapefiles representing streets, one shapefile for each state of my country. All the shapefiles are line based and have the same dbf structure. Is there a way in Map Suite to use the same ShapeFileFeatureLayer for all those shapefiles since I want to represent all those shapefiles the same way? That would make my code cleaner and shorter. And how would I build the spatial indexes? If this is possible, can you show me some sample code on how to accomplish that? Thank you.
Several shapefiles for the same ShapeFileFeatureLayer
Adolfo,
This is exactly the scenario you should use MultipleShapeFileFeatureLayer, 2 ways are supported. The difference lies in the different RtreeIndex files. Try them.
//This represent the same structure shapefiles: AKctycu.shp, NYctycu.shp etc.
string ctycuShapeFilePatten = dataFolder + "\\??" + "ctycu.shp";
//First way.
//string ctycuIndexFilePatten = dataFolder + "\\ctycu.midx";
//Second way.
string ctycuIndexFilePatten = dataFolder + "\\??ctycu.midx";
MultipleShapeFileFeatureLayer.BuildIndex(ctycuIndexFilePatten, ctycuIndexFilePatten, BuildIndexMode.DoNotRebuild);
MultipleShapeFileFeatureLayer ctycuLayer = new MultipleShapeFileFeatureLayer(ctycuShapeFilePatten, ctycuIndexFilePatten);
ctycuLayer.Name = "County";
ctycuLayer.DrawingQuality = DrawingQuality.HighQuality;
ctycuLayer.ZoomLevelSet.ZoomLevel12.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 242, 239, 233));//GeoColor.FromArgb(255, 233, 232, 214));
ctycuLayer.ZoomLevelSet.ZoomLevel12.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Any more questions just let me know.
Thanks.
Yale
Hi,
MultipleShapeFileFeatureLayer is very very cool and great time saver. I ran into a problem with the limitations of the patterns though.
I have a directory of shapefiles ("CA_county.shp", "AZ_county.shp", …) (all 50),
and I would like to be able to include 2-3 states into a MultipleShapeFileFeatureLayer.
Right now I can only include all 50 of them ("??_counties.shp").
I am guessing the limitation comes from the internal call to System.IO.Directory.GetFiles(path, searchPattern).
So I suggest another overload on BuildIndex() and the constructor that accepts a string[] of shapefiles and string[] of indexfiles to use.
Then I could use the following:
string[] shapeFiles = new string[] { "C:\CA_counties.shp", "C:\AZ_counties.shp" };
string[] indexFiles = new string[] { "C:\CA_counties.midx", "C:\AZ_counties.midx" };
MultipleShapeFileFeatureLayer.BuildIndex(shapeFiles, indexFiles, BuildIndexMode.DoNotRebuild);
MultipleShapeFileFeatureLayer layer = new MultipleShapeFileFeatureLayer(shapeFiles, indexFiles)
Thanks,
Rob
Rob,
Your suggestions are very interesting; we will consider it very carefully.
Up to now, I think one way to go around this problem is to create a new folder and copy those 2 or 3 files into it before creating the MultiShapeFileFeatureLayer.
Thanks for your suggestions.
Yale
Yale,
I am using the work around of copying shapefiles for demos, but it is not feasible to use in production. Each client of ours can have access to 1 to 50 states, depending on their contract. So between the different types of shapefiles, and the different combination of states, this would quickly become a multi-terabyte mess of duplicated data.
Side note: we will be launching our new product in January, and will need some way to handle this by then.
-Rob
Rob,
Thanks for your post and answers.
I have discussed this new feature with our director, and we agree to add this new feature. I have added this item to our working track system and hope it will be available soon .
Any more questions just feel free to let me know.
Thanks.
Yale
Excellent! Can’t wait
Rob,
I wanted to fill you in on this update as have some info. We have the go ahead to do the change and I am pretty sure it will get completed early next week. One issue is that we are int he middle of improving our auto-build system so it might be a week and a half before we can get the fix to you. We are enhancing our auto build to make them run faster and to also build a branched version of the last public release that is a bug fix only version. Soon we will have two versions you can get which will be a bug fix only and a development build. Sorry for the delay on this but it is going to be really cool when we have the updates in place.
David
Is there a build with this feature available yet?
-Rob
Rob,
We have added the following API while I am sorry to say that we have to wait some days for the building system ready, as David said , the building system is re-constructed and now it is closed to end.
public MultipleShapeFileFeatureSource(string[] multipleShapeFiles, string[] multipleShapeFileIndexes)
Sorry for the inconvinience for now.
Thanks.
Yale
Sounds good. Can you notify me when the build is available? By the way, I am a Web user, even though we are in the Desktop forums.
Also, don’t forget to add support into MultipleShapeFileFeatureLayer.BuildIndex()
One question related to the midx files. Are they tied to anything other than the single shapefile they are indexing? If I build midx indexes for each states shapefile, can I use the same midx’s for any combination of shapefiles in the MultipleShapeFileFeatureLayer? Or are they somehow tied to the combination of shapefiles?
Thanks,
Rob
Rob,
Thanks for your remiding.
There are 2 ways for midx. One is each shape file will related to one midx file, while the other way is multiple shape files are related with one midx file.
Any more questions just let me know.
Thanks.
Yale
Any update on the build system? I’m getting a ton of pressure from above, since I relayed to them your new build would be here back in Dec.
Rob,
We have done it but we don’t have plan to release new version recently. If you eager to get it immeditely, Please contact support@thinkgeo.com to request the version 3.1.364.0 temperary dll package.
We also made a sample to show how to use the new API, you can find it at Code Community code.thinkgeo.com/projects/show/multiindex
Please let me know if you have questions.
Thanks
James
Rob,
Please see your FTP account for the 3.1.364 build that James references.
Thanks!
By the way, this works great!
Rob,
Thanks for the feedback:). Also here is our new Daily Builds strategy which help user get the latest build, please have a look.
gis.thinkgeo.com/Support/Dis...fault.aspx
Thanks,
Ben
I found a problem with both MultipleShapeFileFeatureLayer.QueryTools.GetFeaturesNearestTo() and MultipleShapeFileFeatureLayer.FeatureSource.GetFeaturesNearestTo().
They both seem to only query the first shapefile in the collection. By the way, I am querying line based (streets) shapefiles, and I am using the MultipleShapeFileFeatureLayer(string[] multipleShapeFiles, string[] multipleShapeFileIndexs) constructor.
Can this be fixed?
Rob,
I double checked the code logic for the GetFeaturesNearestTo API in the MultipleShapefileFeatureSource, it did try to get only one part from each shape file. If the problem is still being there, could you send us a sample to demonstrate the issue? It definitely will make us easily to figure out the problem and get it fixed. If you want, you can send the sample to our support (support@thinkgeo.com) and asked to forward to Yale.
Any more questions please feel free to let me know.
Thanks.
Yale
I emailed the shapefiles to support, and here is the sample code that demonstrates the problem:
// change this
string dir = ConfigurationManager.AppSettings["MapsRoot"];
string[] shapeFiles = new string[] { dir + "az_A.shp", dir + "ca_A.shp" };
string[] indexFiles = new string[] { dir + "az_A.midx", dir + "ca_A.midx" };
MultipleShapeFileFeatureLayer.BuildIndex(new string[] { shapeFiles[0] }, new string[] { indexFiles[0] }, BuildIndexMode.DoNotRebuild);
MultipleShapeFileFeatureLayer.BuildIndex(new string[] { shapeFiles[1] }, new string[] { indexFiles[1] }, BuildIndexMode.DoNotRebuild);
MultipleShapeFileFeatureLayer lineLayer = new MultipleShapeFileFeatureLayer(shapeFiles, indexFiles);
PointShape southernCaliforniaPoint = new PointShape(-116.9, 34.2);
string fipsCodeColumnName = "FIPS_CNTY";
lineLayer.Open();
Collection<Feature> features = lineLayer.FeatureSource.GetFeaturesNearestTo(southernCaliforniaPoint, GeographyUnit.DecimalDegree, 1, new string[] { fipsCodeColumnName });
lineLayer.Close();
if (features.Count > 0)
{
// first 2 chars of FipsCode tell us which state the feature is in
string fipsCode = features[0].ColumnValues[fipsCodeColumnName];
if (fipsCode.StartsWith("06")) // california
{
// code should end up here
bool wtf = true;
}
else if(fipsCode.StartsWith("04")) // arizona
{
// but instead, it ends up here
bool wtf = true;
}
}