|
POST
|
Sorry, forgot to show you where the point is appearing. See attached. I see what you mean! In that case, let's take Alexander's advice and use the LabelPoint of the pArea. Change this:
pPoint = pArea.Centroid
To this:
pPoint = pArea.LabelPoint
... View more
10-19-2011
06:34 AM
|
0
|
0
|
834
|
|
POST
|
I am not sure why you are seeing centroids outside of any selected polygons --- it really isn't the centroid of the polygon then, right? Not sure what you have going on there. I did some limited testing of the code below and it places graphic points at the centroid locations of each of the selected polygons, or at least what appears to be the centroid. None are placed outside of any selected polygon.
Dim pGraphics As IGraphicsContainer
pGraphics = pMap
Dim pMarkerElem As IMarkerElement
pMarkerElem = New MarkerElement
Dim pElement As IElement
pElement = pMarkerElem
Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
pFSelection = pMap.Layer(0)
pSelectionSet = pFSelection.SelectionSet
''set the pfeaturecursor
pFCursor = Nothing
''Get a cursor from the selected features
pSelectionSet.Search(Nothing, False, pFCursor)
Dim pPoly As IPolygon
Dim pArea As IArea
Dim pPoint As IPoint
Dim pFeat As IFeature
pFeat = pFCursor.NextFeature
Do Until pFeat Is Nothing
pPoly = pFeat.ShapeCopy
pArea = pPoly
pPoint = pArea.Centroid
pElement = New MarkerElement
pElement.Geometry = pPoint
pGraphics.AddElement(pElement, 0)
pFeat = pFCursor.NextFeature
Loop
pDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, Nothing, Nothing)
pDoc.ActiveView.Refresh()
... View more
10-19-2011
05:28 AM
|
0
|
0
|
3849
|
|
POST
|
Hi, I'm C# programmer and have some knowledge about working with ArcGIS Desktop 10. But I'm new at ArcObjects in C#. Can somebody give me an example, how I can add a new layer to existing MXD map in C# from XY table? Examples which I found before didn't work. Can I do this from dataset or we need to generate some extra files like TXT or XLS? Thank you When you say "dataset", do you mean x/y values in an ADO.NET DataSet/DataTable?
... View more
10-18-2011
03:40 PM
|
0
|
0
|
2084
|
|
POST
|
The feature class is a personal geodatabase featureclass, I'm not dealing with SDE featureclasses so unfortunately your second post doesn't apply, but thanks for looking into this. But from your original post you say that this occurs with SDE FeatureClasses... [INDENT]"...I've noticed users finding this occurring with SDE databases but not with PGDBs - has anyone experienced this?"[/INDENT] I wonder if the issue is that because you have a large number of layers in the TOC that something isn't slipping by you that you think is something else (like an SDE FC or something and is the one that is causing problems). In which case you might want to check/verify the type prior to checking it's path. The help has an example:
Public Function GetPathForALayer(ByVal layer As ESRI.ArcGIS.Carto.ILayer) As System.String
If layer Is Nothing OrElse Not (TypeOf layer Is ESRI.ArcGIS.Geodatabase.IDataset) Then
Return Nothing
End If
Dim dataset As ESRI.ArcGIS.Geodatabase.IDataset = CType(layer, ESRI.ArcGIS.Geodatabase.IDataset) ' Explicit Cast
Return (dataset.Workspace.PathName & "\" & dataset.Name)
End Function
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_Path_for_a_Layer_Snippet/004900000092000000/
... View more
10-18-2011
05:58 AM
|
0
|
0
|
1091
|
|
POST
|
There's lots of resorces on the ArcGIS Resources pages dedicated to ArcGIS Engine application development. Looks like .NET (VB, C#, etc..), C++ and Java are the choices in programming languages: http://resources.arcgis.com/content/arcgis-engine/10.0/about
... View more
10-17-2011
05:25 AM
|
0
|
0
|
546
|
|
POST
|
Also, am I getting eastings and northings or latitude and longitude here? Thanks again for your generous help. You are probably not going to like hearing this, but its not quite that simple. You are getting the x/y of the point's spatial reference (I have no way of knowing what that is, it is your point layer). To make sure you are getting the Lat/Lon, you will have to make sure the point has a geographic coordinate system assigned and in order to do this I think you will have to project it from something. ...In essence, you will need to know where you are coming from in order to get it to project to something. Luckily the old forums are full of examples. You might start here: http://forums.esri.com/Thread.asp?c=93&f=993&t=227713&mc=1#msgid691091 Found with these search terms: IPoint.X
... View more
10-14-2011
09:28 AM
|
0
|
0
|
3849
|
|
POST
|
If your Command/Tool does not have any registration code and you are manually "Add From File" via the Customize dialog, then try to add the type library (.tbl) file instead of the .dll file. http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000040v000000
... View more
10-14-2011
08:00 AM
|
0
|
0
|
856
|
|
POST
|
Also, after looking at some older posts I noticed for VBA that pDoc should be set to "ThisDocument" instead of how the OP has it:
Set pDoc = Application.Document
Should this be:
Set pDoc = ThisDocument
Sorry it's been a long time since I've used VBA and just trying to help out as best I can!
... View more
10-14-2011
07:26 AM
|
0
|
0
|
1809
|
|
POST
|
Also, you have specified the lat and lon variables as LONG data type. Why? This would produce a whole number, which I don't know of any Latitude/Longitude coordinate that is a whole number. Is that what you want?
... View more
10-14-2011
06:29 AM
|
0
|
0
|
1809
|
|
POST
|
The pSelectionSet.Search(Nothing, False, pFCursor) is appearing in red. I am guessing it should be:
pFCursor = Nothing
pFCursor = pSelectionSet.Search(Nothing, False, pFCursor)
No the way you have the pFCursor would not work --- the code I posted works just fine for me. I really don't know why it would appear in red or do I even know what that means. I am using Visual Studio 2008 with all of the proper SDK's installed, along with ArcGIS v10.
... View more
10-14-2011
06:25 AM
|
0
|
0
|
1809
|
|
POST
|
But now I am getting a run-time error: Run-time error:91 Object Variable or With Block Variable not set When I click on debug, it takes me to the following line in code: Set pFeat = pFCursor.NextFeature Thanks again. That's probably because you are not setting pFCursor anywhere (I don't think I provided that in my original post. sorry I am picking snippets from my own implementation which is different). See if this helps/completes the code. Sub CreateCentroid()
Dim pDoc As IMxDocument
Dim pMap As IMap
Set pDoc = Application.Document
Set pMap = pDoc.FocusMap
Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
Set pFSelection = pMap.Layer(0)
pSelectionSet = pFSelection.SelectionSet
''set the pfeaturecursor
pFCursor = Nothing
''Get a cursor from the selected features
pSelectionSet.Search(Nothing, False, pFCursor)
Dim pPoly As IPolygon
Dim pArea As IArea
Dim pPoint As IPoint
Dim lat As Long
Dim lon As Long
Dim pFeat As IFeature
Set pFeat = pFCursor.NextFeature
Do Until pFeat Is Nothing
Set pPoly = pFeat.ShapeCopy
Set pArea = pPoly
Set pPoint = pArea.Centroid
lat = pPoint.X
lon = pPoint.Y
Set pFeat = pFCursor.NextFeature
Loop
End Sub
... View more
10-14-2011
06:05 AM
|
0
|
0
|
1809
|
|
POST
|
First, are you declaring pDoc and pMap somewhere else?
Dim pDoc As IMxDocument
Dim pMap As IMap
If not, you will need to put these at the top of your CreateCentroid Sub or make them Private variables in the entire class. It has been a long time since working with VBA, but I don't think this will work:
pDoc = m_pApp.Document
Try to replace it with:
Dim pDoc As IMxDocument
pDoc = Application.Document
... View more
10-14-2011
03:54 AM
|
0
|
0
|
2675
|
|
POST
|
I think I need ArcGIS Visual Studio Integration Framework! Is there any other way I can acheive this? i.e. build a custom tool based on a model? Just fyi, from: http://edndoc.esri.com/arcobjects/9.2/NET/73516929-d390-456c-84bc-c8f8a58b645a.htm "...The ArcGIS Visual Studio IDE Integration Framework is installed as part of the Software Developer Kit (SDK) for .NET for each ArcGIS product and is an optional feature during installation. This framework is available for Visual Studio 2005, Visual Basic 2005 Express, Visual C# 2005 Express, and Visual Web Developer 2005 Express editions." So, I am not certain if the VS IDE Framework is what you need. I do believe that the reason why no ArcGIS Project templates show up is because you simply do not have the ArcGIS .NET SDK installed.
... View more
10-13-2011
06:34 AM
|
0
|
0
|
2675
|
|
POST
|
James, I am trying to create an Add-In following this link: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001ms000000 But I cannot find ArcGIS node under project type. What do I need to do in order to get that in Visual Studio? I apologise for these questions as I am a bit of a beginner in Arc. I will be adding this to ArcMap and hopefully, once it is up and running, my colleagues will be using it too. Thanks. I *think* this is because you do not have the ArcGIS .NET SDK ("Developer Kit") installed. Can someone else confirm this?
... View more
10-13-2011
06:19 AM
|
0
|
0
|
2675
|
|
POST
|
Not sure if there is a forum specific to Python, but if you are going to write something similar to VBA, you'd probably want either create an Add-In or a COM implementation (I assume this is for extending ArcMap?) In any event, here is some code that would get the centroid (and lat/lon values of that centroid) of a selected polygon feature for the first layer in the TOC.
pDoc = m_pApp.Document
pMap = pDoc.FocusMap
''get the selection from the layer
Dim pFCursor As IFeatureCursor
Dim pSelectionSet As ISelectionSet
Dim pFSelection As IFeatureSelection
pFSelection = pMap.Layer(0)
Dim pPoly As IPolygon
Dim pArea As IArea
Dim pPoint As IPoint
Dim lat As Decimal 'not sure exactly which number format you'd want to use
Dim lon As Decimal
Dim pFeat As IFeature = pFCursor.NextFeature
Do Until pFeat Is Nothing
pPoly = pFeat.ShapeCopy
pArea = pPoly
pPoint = pArea.Centroid
lat = pPoint.X
lon = pPoint.Y
pFeat = pFCursor.NextFeature
Loop
this may be a kind of round-about way to get at things, but it does seem to work.
... View more
10-13-2011
04:57 AM
|
0
|
0
|
2675
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|