Showing posts with label ESRI. Show all posts
Showing posts with label ESRI. Show all posts

Monday, February 9, 2009

How to generate GML string for featrues available in Feature Layer

GML stands for Geographic Markup Language.
GML is very similar to XML, where we describe the geo position coordinates, type, etc in a standard xml format called as GML.
For this we can find an interface called “IGMLConversion” in “ESRI.ArcGIS.TrackingAnalyst” package.

I have written a tool which look like



I have placed my tool with caption as “GIS Demos”, so you can find “GIS Demos” button in Arc map interface while importing this .tlb file.




Now if we click on the export button by selecting a feature layer name populated in the drop down list,



As soon as I provide a file name and say “save” in the file dialog.
It generates GML string for all available features in the selected feature layer and writes them to the file name provided and opens the same file.



Thursday, February 5, 2009

How to create Polygon features associated or parallel to given Line features

Example:-




So we need 2 feature layers,
1) Line feature layer (Layer Name – Lines) as input which has some random line or poly line features.
2) Polygon feature layer (Layer Name – Poly) as output which will be updated or inserted with polygon features based upon available line features in given input (Lines) feature layer.
Input parameters:-





This tool has been built in c#.net whose .tlb file is imported into Arc Map to perform the given actions.
The feature classes drop down lists or combo boxes are loaded with all the available feature layers in the given map or .mxd document.
I have placed my tool in GML name space, so you can find GML button in Arc map interface while importing this .tlb file.
Output:-





Before generating polygon





After generating polygon using my tool


Tuesday, December 30, 2008

How to get features with in an Envelope – ESRI

When we load .mxd or map file onto map control, we can find features from different feature layers been spatially distributed.
So to find a set of features which belong to a specific feature class and enclosed with in an envelope, we can write a generic function that accepts the envelope and feature layer to find features in specific feature layer.

Step 1:-
Write a function Considering IEnvelope , IFeatureLayer, MapControl as Input Parameters.
Step 2:-
Run a spatial query using ISpatailFilter interface for the feature class of the given Input feature layer with geometry as given envelope.
Note:-For SpatialRelUse (Spatial relation)
Assign enumeration values from esriSpatialRelEnum
Ex:- esriSpatialRelEnum. esriSpatialRelIntersects for considering all featuers in the feature layer which intersect the given input envelope.
Step 3:-
Query feature class with the above Spatail filter object and retrieve feature cursor.

We can retrieve feature by feature from the returned feature cursor and perform specific required operations.

Function :-
private IFeatureCursor GetFeatures(IFeatureLayer argFeatureLayer, IEnvelope argEnvelope, IMap argMap)
{
if (argEnvelope != null && argFeatureLayer != null && argFeatureLayer.FeatureClass != null && argMap != null)
{
ISpatialFilter objSpatialFilter = new SpatialFilterClass();
objSpatialFilter = new SpatialFilter();
objSpatialFilter.Geometry = (IGeometry)argEnvelope;
objSpatialFilter.GeometryField = "Shape";
objSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
return argFeatureLayer.FeatureClass.Search(objSpatialFilter, false);
}
return null;
}

Example :-

To select a set features spatially intersecting the given envelope.

private void SelectFeatures(IFeatureLayer argFeatureLayer, IFeatureCursor argFeatCursor)
{
if (argFeatCursor != null)
{

IFeature pFeature = null;
while ((pFeature = argFeatCursor.NextFeature()) != null)
{
Map.SelectFeature(argFeatureLayer, pFeature);
}
}
}

O/p





Wednesday, December 24, 2008

How to find whether geometry is with in Feature class extent ESRI ?

Every feature class has its own extent for spatially distributing its features.

So we can check whether a given geometry lies in a given extent or envelope.

public static bool IsWithinExtent(IGeoDataset geoDataset, object geometry)
{
IGeometry pGeometry;
IRelationalOperator pRelOp;
try
{
//If given geometry is element then tracing its gemoetry to find
//with in extent
if (geometry is IElement)
pGeometry = ((IElement)geometry).Geometry;
//If given geometry is dimension, then considering all points lieing at the
//dimension feature boundaries
else if (geometry is IDimensionShape)
{
//Extracting the geometry of the dimension feature
IDimensionShape pDimShape = (IDimensionShape)geometry;
IPointCollection pPointCol = new PolygonClass();
object pBefore = Type.Missing;
object pAfter = Type.Missing;
//Creating a closed polygon with lines joining the dimension line point,
//dimension begin point, dimension end point
pPointCol.AddPoint(pDimShape.DimensionLinePoint, ref pBefore, ref pAfter);
pPointCol.AddPoint(pDimShape.BeginDimensionPoint, ref pBefore, ref pAfter);
pPointCol.AddPoint(pDimShape.EndDimensionPoint, ref pBefore, ref pAfter);
//Then taking geometry of finally created polygon
pGeometry = (IGeometry)pPointCol;
}
else
//Taking the exact geometry of the given object
pGeometry = (IGeometry)geometry;
//relation operator helps tp spatially licate the geometry
// and then chek its extent
pRelOp = (IRelationalOperator)pGeometry;
if (pRelOp.Within(geoDataset.Extent))
return true;
else
//Throughing coordinates out of boundary when give geometry
// does not lie with in the feature class extent
throw new Exception(conCoordsOutofBound);
}
catch
{
throw new Exception(conCoordsOutofBound);
}
}










Sunday, December 21, 2008

How to spatially select a feature in Map – ESRI?

When we load map control with map (.Mxd) file, there could be many layers available.
So to select a specific feature from a layer, we need to know the feature class to which this feature belongs.

To get the feature class of a feature, we can say [feature object].Featureclass.
Ex: - argFeature.Featureclass.

Now we need to iterate through each layer available on the loaded map file, then we need to find the layer that loads features from the above feature class.

I would like to update such function which expects map and feature as input parameters to spatially select a feature in the given map.


public static void setSelected(IFeature pFeature,IMap pMap)
{
try
{
IFeatureLayer pFeaturelayer;
ICompositeLayer pCompositeLayer;
IFeatureClass pFeatureClass;
int layerCount;
int compositeLayerCount;

//Loop to iterate through each layer in the given map
for (layerCount = 0; layerCount <= pMap.LayerCount - 1; layerCount++)
{
//If retrieved layer is a group layer (layer having a group of layers in it)
if (pMap.get_Layer(layerCount) is IGroupLayer)
{
pCompositeLayer = (ICompositeLayer)pMap.get_Layer(layerCount);
//Looping through each layer in the group layer
for (compositeLayerCount = 0; compositeLayerCount <= pCompositeLayer.Count - 1; compositeLayerCount++)
{
//Checking if the layer is feature layer (a map layer that consists of features
if (pCompositeLayer.get_Layer(compositeLayerCount) is IFeatureLayer)
{
pFeaturelayer = (IFeatureLayer)pCompositeLayer.get_Layer(compositeLayerCount);
pFeatureClass = pFeaturelayer.FeatureClass;
//Checking with the feature class name asscoiated with the layer is same as
//given feature's feature class
if (pFeatureClass != null && pFeature != null)
{
if (((IDataset)pFeatureClass).Name == ((IDataset)(IFeatureClass)(pFeature.Class)).Name)
{
//If feature class name's are equal
pMap.SelectFeature((ILayer)pFeaturelayer, pFeature);
}

}
}
}
}
//Checking if the layer is feature layer (a map layer that consists of features
else if (pMap.get_Layer(layerCount) is IFeatureLayer)
{
pFeaturelayer = (IFeatureLayer)pMap.get_Layer(layerCount);
pFeatureClass = pFeaturelayer.FeatureClass;
//Checking with the feature class name asscoiated with the layer is same as
//given feature's feature class
if (pFeatureClass != null)
{
if (((IDataset)pFeatureClass).Name == ((IDataset)(IFeatureClass)(pFeature.Class)).Name)
{
//If feature class name's are equal
pMap.SelectFeature((ILayer)pFeaturelayer, pFeature);
}
}
}

}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message +" setSelected",Constants.DIALOG_TITLE,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
Please click in below image links to look at comments