SampleExportNamer.cs
Copy Code
|
|
---|---|
//----------------------------------------------------------------------------- //Miner and Miner Consulting Engineering, Inc. //Copyright 2003 //----------------------------------------------------------------------------- //Module Name: SampleNamer //Description: an example of a component which // returns a filename based on Feature OIDs // for use with ArcFM Map Production // // //----------------------------------------------------------------------------- using System.Runtime.InteropServices; using System; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using Miner.ComCategories; using Miner.Geodatabase; using Miner.Interop; namespace Miner.Samples { [ComVisible(true)] [Guid("07995206-AE0F-439b-810C-F3169420ED70")] [ComponentCategory(ComCategory.MMMapProductionNamers)] public class SampleExportNamer : IMMNamer, IPersistVariant { #region Private Members //Member data // optional: the feature class caller initialized us with private IFeatureClass _featureClass; // optional: the property set caller initialized us with private IPropertySet _namerProperties; #endregion Private Members #region IMMNamer Implementation public void Initialize(IFeatureClass FeatureClass, IPropertySet NamerProperties) { //Purpose: set member variables and initialize any counters etc here _featureClass = FeatureClass; _namerProperties = NamerProperties; } public string Name { get { // used by Map Prod UI - this is the name that shows up in the combo box return "Sample Export Namer (.NET)"; } } public IPropertySet NamerProperties { get { // return a pointer to the property set we will use to generate the file name return _namerProperties; } } public string NextFileName(IGeometry PlotExtent, int PageNumber, int TileNumber, string SheetID, string BaseFileName, string BaseFileExtension) { //Purpose: return a string of OIDs of mapgrids in the extent ISpatialFilter spatialFilter = new SpatialFilter(); IArea area = PlotExtent.Envelope as IArea; spatialFilter.Geometry = area.Centroid; spatialFilter.GeometryField = "SHAPE"; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursor = _featureClass.Search(spatialFilter, false); IFeature feature = featureCursor.NextFeature(); if (feature != null) { return BaseFileName + "_oid_" + Convert.ToString(feature.OID) + "_" + TileNumber + "." + BaseFileExtension; } return BaseFileName + PageNumber + "." + BaseFileExtension; } public string NextFileName(IGeometry PlotExtent, int PageNumber, int TileNumber, string SheetID, string BaseFileName) { return NextFileName(PlotExtent, PageNumber, TileNumber, SheetID, BaseFileName, ""); } public string NextFileName(IGeometry PlotExtent, int PageNumber, int TileNumber, string SheetID) { return NextFileName(PlotExtent, PageNumber, TileNumber, SheetID, "", ""); } public string NextFileName(IGeometry PlotExtent, int PageNumber, int TileNumber) { return NextFileName(PlotExtent, PageNumber, TileNumber, "", "", ""); } public string NextFileName(IGeometry PlotExtent, int PageNumber) { return NextFileName(PlotExtent, PageNumber, 0, "", "", ""); } public string NextFileName(IGeometry PlotExtent) { return NextFileName(PlotExtent, 0, 0, "", "", ""); } public string NextFileName() { return NextFileName(null, 0, 0, "", "", ""); } /// <summary> /// Returns true if the feature class is supported. Note that some callers may require support for /// all feature classes and pass nothing, this is generally called before Initialize. /// </summary> /// <param name="FeatureClass">Feature class to check.</param> /// <returns>Returns true if the feature class is supported.</returns> public bool SupportsFeatureClass(IFeatureClass FeatureClass) { bool result = false; // For our example, we will only support grid features IObjectClass pObjectClass = FeatureClass; if (pObjectClass != null) { result = ModelNameManager.Instance.ContainsClassModelName(FeatureClass, "MapGrid"); } return result; } #endregion IMMNamer Implementation #region IPersistVariant Implementation public UID ID { get { // return ProgID of this component UID uid = new UID { Value = "DevSampleNamers.SampleExportNamer" }; return uid; } } public void Save(IVariantStream Stream) { // individual properties could be extracted and saved if so desired // note: always use a version ID if persisting data // this example doesn't persist anything, but if it did... //Stream.Write _persistVersion //Stream.Write _namerProperties } public void Load(IVariantStream Stream) { // always read the version number first.... //int version = Convert.ToInt32(Stream.Read()); //if(version == 1) _namerProperties = Stream.Read() as IPropertySet; } #endregion IPersistVariant Implementation } } |