void _listener_OnKeyPressed(object sender, KeyPressedArgs e)
{
_listener.UnHookKeyboard();
_listener.HookKeyboard();
}
Following is the video from on Low Level Keyboard Hook in C# / .NET"
1: public void FindPolygonBelongsToPoint()
2: {
3: try
4: {
5: var shapePath = @"C:\Locations_WGS84.shp";
6: Ogr.RegisterAll();
7: OSGeo.OGR.Driver shapeDriver = Ogr.GetDriverByName("ESRI Shapefile");
8: DataSource shape = shapeDriver.Open(shapePath, 0);
9: Layer layer = shape.GetLayerByIndex(0);
10:
11: Feature polygonFeature = layer.GetNextFeature();
12:
13: long featureCountInLayer = layer.GetFeatureCount(1);
14: for (int i = 1; i <= featureCountInLayer; i++) {
15:
16: Geometry polygonGeom = polygonFeature.GetGeometryRef();
17:
18: string coordinates = "POINT (-100.726 38.995)";
19:
20: SpatialReference spatialRef = layer.GetSpatialRef();
21: Geometry point = Ogr.CreateGeometryFromWkt(ref coordinates, spatialRef);
22:
23: bool isInside = point.Within(polygonGeom);
24:
25: if (isInside)
26: {
27: var val = polygonFeature.GetFieldAsString(4);
28: Console.WriteLine("Found one");
29: }
30:
31: polygonFeature = layer.GetNextFeature();
32: }
33:
34: }
35: catch (Exception ex)
36: {
37:
38: Console.WriteLine(ex.Message);
39: }
40:
41: }
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Catalog;
using ESRI.ArcGIS.CatalogUI;
using ESRI.ArcGIS.Desktop.AddIns;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using Microsoft.SqlServer.Types;
namespace Test.Addin.ArcCommands
{
class SelectFeatureTool : ESRI.ArcGIS.Desktop.AddIns.Tool
{
protected override void OnMouseDown(MouseEventArgs arg)
{
IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument;
IActiveView activeView = mxDocument.ActiveView;
IMap map = mxDocument.FocusMap;
ILayer layer = map.get_Layer(0); //Get 1st Layer
IFeatureLayer featureLayer = (IFeatureLayer) layer;
IPoint identifyPoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
ESRI.ArcGIS.Carto.IIdentify identifyLayer = (IIdentify)layer;
IArray array = identifyLayer.Identify(identifyPoint);
int oid = -1;
if (array != null)
{
object obj = array.get_Element(0);
IFeatureIdentifyObj fobj = obj as IFeatureIdentifyObj;
IRowIdentifyObject irow = fobj as IRowIdentifyObject;
IFeature feature = irow.Row as IFeature;
oid = feature.OID;
}
HighlightClickedFeature(featureLayer, oid, activeView);
}
import csv
import itertools
outCombinedStatTxtName ="FormattedTxtResults.csv"
tempCsvFiles = glob.glob(str(TempFolderPath)+'\*.csv')
openedFileList = [open(fn, 'rb') for fn in tempCsvFiles]
readers = [csv.reader(fn) for fn in openedFileList]
result = open(outCombinedStatTxtName, 'wb')
writer = csv.writer(result,delimiter=',')
multipleIndices = False
for row_chunks in itertools.izip(*readers):
tempFormattedRow = list(itertools.chain.from_iterable(row_chunks))
fidIndices = [i for i, x in enumerate(tempFormattedRow) if x == "ID"]
if(len(fidIndices) > 1):
fidIndices.pop(0)
redundantIndices = tuple(fidIndices)
multipleIndices = True
if(multipleIndices):
tempFormattedRow = [ tempFormattedRow[i] for i in xrange(len(tempFormattedRow)) if i not in set(redundantIndices) ]
writer.writerow(tempFormattedRow)
else:
writer.writerow(tempFormattedRow)
result.close()
[fn.close() for fn in openedFileList]
class SelectFeatureTool : ESRI.ArcGIS.Desktop.AddIns.Tool
{
protected override void OnMouseDown(MouseEventArgs arg)
{
IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument;
IActiveView activeView = mxDocument.ActiveView;
IMap map = mxDocument.FocusMap;
ILayer layer = map.get_Layer(0); //Get 1st Layer
IFeatureLayer featureLayer = (IFeatureLayer) layer;
IPoint identifyPoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
ESRI.ArcGIS.Carto.IIdentify identifyLayer = (IIdentify)layer;
IArray array = identifyLayer.Identify(identifyPoint);
int oid = -1;
if (array != null)
{
object obj = array.get_Element(0);
IFeatureIdentifyObj fobj = obj as IFeatureIdentifyObj;
IRowIdentifyObject irow = fobj as IRowIdentifyObject;
IFeature feature = irow.Row as IFeature;
oid = feature.OID;
}
HighlightClickedFeature(featureLayer, oid, activeView);
}
<configuration>
<runtime>
<legacyCorruptedStateExceptionsPolicy enabled="true" />
</runtime>
</configuration>
Step #2[HandleProcessCorruptedStateExceptions] [SecurityCritical]on the top of function you are tying catch the exception
[HandleProcessCorruptedStateExceptions] [SecurityCritical] public IFeatureLayer GetOrCreateFeatureLayer(string path, esriGeometryType type, ISpatialReference sr) {
//body
}
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
public void AddUpdateAttributeField(string oldFeatureFile)
{
DriverUtils.RegisterOgrDriver();
DataSource dataSource;
Layer layer;
var isShapeFile = IsShapeInGdb(oldFeatureFile);
if (isShapeFile)
{
dataSource = Ogr.Open(oldFeatureFile, 1); //second argument in open specifies mode of data, 1 RW & 0 readonly mode
layer = dataSource.GetLayerByIndex(0);
FieldDefn gdalFiedlDefn = new FieldDefn("FID_GDAL",FieldType.OFTInteger);
layer.CreateField(gdalFiedlDefn, 0);
Feature feature = layer.GetNextFeature();
while (feature!= null)
{
feature.SetField("FID_GDAL",feature.GetFID()); // Add FID shapefile
layer.SetFeature(feature);
feature = layer.GetNextFeature();
}
dataSource.FlushCache();
}
else
{
try
{
EnableEsriLiscences();
string gdbPath = Path.GetDirectoryName(oldFeatureFile);
string featureName = Path.GetFileNameWithoutExtension(oldFeatureFile);
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(gdbPath, 1);
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(featureName);
IFields fields = featureClass.Fields;
if (fields.FindField("FID_GDAL") == -1)
{
// Create a Int field called "FID_GDAL" for the fields collection