POST
|
Hi Marianne, You will want to use the field name in the where clause. Ex: uCursor = arcpy.da.UpdateCursor(inFeatures, [ 'OID@', 'SHAPE@', 'GM_LABEL', 'GM_USER_DEF' ], 'SHAPE.LEN < 300' ) Oh, simple as that! Works like a charm, thanks. -- But where is the 'accepted answer' button? And also thanks, xander, this might be useful another time /Marianne
... View more
02-06-2014
07:24 AM
|
0
|
0
|
251
|
POST
|
Hi Forum I have a versioned database, where I want to make short lines longer. So in Python I try to select the short lines like this >>> uCursor = arcpy.da.UpdateCursor(inFeatures, [ 'OID@', 'SHAPE@', 'GM_LABEL', 'GM_USER_DEF' ], 'SHAPE@LENGTH < 300' ) edit = arcpy.da.Editor(arcpy.env.workspace) edit.startEditing() edit.startOperation() which goes without problems but on line = uCursor.next() I get this error Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> RuntimeError: Underlying DBMS error [ORA-04054: databaselink LENGTH does not exist ] [G100.geopoint_line] I tried also this where clause, that works in ArcMap Select by attributes: SHAPE.LEN < 300 Because there is also a field called SHAPE.LEN. I tried with and without quotes with no success. Is it possible at all to make a constraint based on geometry? /Marianne
... View more
02-06-2014
12:46 AM
|
0
|
3
|
359
|
POST
|
Thanks for answering, Matshopp. However, as you can see in my code, I already read the vertex positions from the geometry. Problem is, that Arcpy's access to polyline object properties is readonly, so that I must make a new line and put that into geometry object. I guess it has to do with the granularity of arcpy's methods. I had hoped for another library to exist, which could programmatically go into edit mode more in details. Best regards Marianne
... View more
10-03-2013
02:02 AM
|
0
|
0
|
386
|
POST
|
Hi For a featureclass of polylines with 2 vertices each, I want to be able to keep the line itself, startpoint and the angle, but move endpoint to a specific length. I am doing this in a versioned geodatabase, and currently I can put a new line into the geometry, but the problem is, there are featurelinked annotations which are reset, when the whole line is changed. I wonder whether it is possible, since I already am in edit mode, to just move lastpoint of the existing line? Perhaps this is not possible with arcpy? Best Regards Marianne Wiese
import arcpy, time, traceback
arcpy.env.workspace = 'Database Connections/mbw.sde'
inFeatures = 'G100.geopoint_mbw_20130930/G100.geopoint_line_2'
newLength = 550
n = 0
try:
uCursor = arcpy.da.UpdateCursor(inFeatures, [ 'OID@', 'SHAPE@'])
edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing()
edit.startOperation()
for row in uCursor:
line = row[1]
factor = newLength/line.length
X2 = line.firstPoint.X + factor * (line.lastPoint.X - line.firstPoint.X)
Y2 = line.firstPoint.Y + factor * (line.lastPoint.Y - line.firstPoint.Y)
array = arcpy.Array([line.firstPoint, arcpy.Point(X2,Y2)])
newLine = arcpy.Polyline(array)
row[1] = newLine
uCursor.updateRow(row)
n += 1
if (n % 1000 == 0):
print time.strftime('%H:%M:%S'), ': ', n
except:
tb = traceback.format_exc()
print tb
finally:
del uCursor
edit.stopOperation()
edit.stopEditing(True)
del edit
print 'all done'
... View more
10-02-2013
08:21 AM
|
0
|
2
|
3268
|
POST
|
It turns out that the guy who published my service had turned off the cache accidentally. Tiles work fine now. I wish I could remove this question? Best
... View more
10-30-2012
12:49 AM
|
0
|
0
|
145
|
POST
|
Hello all I am trying to fetch tiles from our ArcGis Server 10.1 Service using the REST interface. We have a cached map service and according to the help here: �??Unlike other types of OGC services, there is no WMTS capability option to enable when creating a cached map or image service; WMTS is always enabled.�?� I can access for example the Identify service Through REST like this: (example, not working) http://<Mapserverurl>/identify?imageDisplay=400,400,96&tolerance=1&geometry=-25000,7955000&mapExtent=-50000,7930000,0,7980000&layers=all:14 However when I try to get the capabilities and see which tilematrixset was used (custom) http://<Mapserverurl>/WMTS/1.0.0/WMTSCapabilities.xml I get HTTP 400 The request sent by the client was syntactically incorrect(). It seems to work in ESRI�??s documentation here, so I wonder if there is something wrong with our service. Any hint, as to what we are missing? Best regards Marianne B. Wiese
... View more
10-29-2012
03:43 AM
|
0
|
1
|
339
|
POST
|
Hello there I think I can answer my own question now. It works for me, if I put this code in the init() method of an Apllication Extension that loads automatically at startup. Now I get messages both on newDocument and on openDocument Events. It does not seem necessary to forward the super.specificEvent(). /Marianne
... View more
02-06-2012
12:30 AM
|
0
|
0
|
108
|
POST
|
Hi Forum I am porting a Tool for ArcMap to a Java Addin, and I want to listen to Document events. In the Tools init() function, I do the following, which I found here: ((MxDocument)mxDoc).addIDocumentEventsListener(new IDocumentEventsAdapter(){
@Override public void openDocument(IDocumentEventsOpenDocumentEvent e){
JOptionPane.showMessageDialog(null, "Hey: Document opened!");
}
}); However, with this code in its init() function, ArcMap hangs and never opens any Document. ArcMap did not hang when I tried the newDocument event instead, however a Document that is closed and re-opened will not fire the the newDocument Event. So, if someone could answer any of my questions here, that would be nice: 1) Are we supposed to fire a super.openDocument(e); after having done our own logic? I tried that, but it did not seem to change anything. 2) Could it be, that I should rather listen to Events in an Extension than in this Tool? It might be, that Extensions are loaded first.. 3) Any other suggestions? In the hope of an answer Marianne Wiese
... View more
02-05-2012
09:48 AM
|
0
|
1
|
623
|
POST
|
Hello Forum I try to implement a custom renderer, that will render a polygon featureclass with unique values. To start, I simply have hardcoded som colors. My draw method code goes like this:
// How to render
public void draw(IFeatureCursor featureCursor, int drawPhase, IDisplay display, ITrackCancel trackCancel) throws IOException,AutomationException {
try {
int index = featureCursor.findField("GM_LABEL");
if (legendID == 1) {
IFeature feature = featureCursor.nextFeature();
display.setSymbol(blueSymbol());
do{
display.drawPolygon(feature.getShape());
feature = featureCursor.nextFeature();
}while (feature != null);
}
if (legendID == 2) {
renderer.setSymbolByRef(greenSymbol());
renderer.draw(featureCursor, drawPhase, display, trackCancel);
}
if (legendID == 3) {
uvRenderer.setFieldCount(1);
uvRenderer.setField(0, "GM_LABEL");
uvRenderer.setDefaultSymbol(redSymbol());
uvRenderer.setUseDefaultSymbol(true);
uvRenderer.addValue("LAK", null, blueSymbol());
uvRenderer.setLabel("LAK", "Blue");
uvRenderer.draw(featureCursor, drawPhase, display, trackCancel);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return;
}
This is a desktop extension in java. The first option draws directly to display as in the custom renderer example, works well. The second option works via a simple renderer, works well too. The third option is a try to use a Unique Value Renderer, does not render anything. The polygons are not rendered, screen becomes white. Does anybody know, if I am missing something, or if it is not possible to reference another renderer from inside the draw method. Any answer appreciated Marianne B. Wiese
... View more
08-15-2011
09:06 AM
|
0
|
0
|
542
|
POST
|
Hello Forum I have a custom renderer, with a combobox to choose between differerent renderers. It does work as far as the layer gets rendered the first time a selection is done, and the Update button gets disabled. I would like the Update button to be enabled again when I change the selection in the combobox. How can that be done? This button is a general button for all property pages, outside the UI in the custom renderer project. Best Regards Marianne B. Wiese
... View more
08-15-2011
06:48 AM
|
0
|
2
|
621
|
POST
|
Hello Thanks for the answer Sankar. However, I am not even trying to save the document yet, so I should not need to save the symbol. I was testing it on several feature layers, and it would become green the first time I start ArcMap, but the following times it would go red. Also, today there is nothing wrong, the green symbol is used every time, i try. :confused: Really strange, I havent even rebooted. I checked in a license I had borrowed, thats all. Sorry to have asked about a problem I can't reproduce now. I tried at least 5 times the other day though. I think I will continue with Java, as long as it works. Best Regards Marianne Wiese
... View more
07-19-2011
09:21 AM
|
0
|
0
|
147
|
POST
|
Hello Forum I am trying to make a custom renderer as a Java add-in. I made the following very simple code, which paints all polygons green. The strange thing is, that each time i compile this program, it will work the first time I try it out in ArcMap. If I close restart ArcMap, then all polygons get painted in red by this Add-in, which I guess is a sort of fall back behaviour. No error is catched, and the printlines in the draw method are both printed to the console. I make the greenFillSymbol new each time. So I do not understand this behaviour at all. My question is, if anyone out there is actually making Java Add-ins for Desktop extensions? It may be, that I should revert to C++, and wait for another version of ArcGIS before changing to Java. I have attached the sorce. Best Regards Marianne Wiese
package dk.geus;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.IOException;
import com.esri.arcgis.carto.*;
import com.esri.arcgis.display.*;
import com.esri.arcgis.geodatabase.*;
import com.esri.arcgis.geometry.*;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.system.*;
import com.esri.arcgis.interop.extn.ArcGISExtension;
@ArcGISExtension
public class LegendRenderer implements IFeatureRenderer {
private static final long serialVersionUID = 1L;
public LegendRenderer() { }
public SimpleFillSymbol greenSymbol() {
SimpleFillSymbol greenFillSymbol = null;
try {
greenFillSymbol = new SimpleFillSymbol();
greenFillSymbol.setStyle(esriSimpleFillStyle.esriSFSSolid);
greenFillSymbol.getOutline().setWidth(0.4);
IColor greenColor = new RgbColor();
greenColor.setRGB(0x00ff00);
greenFillSymbol.setColor(greenColor);
} catch (Exception e) {
e.printStackTrace();
}
return greenFillSymbol;
}
// Available only for specific geometry types
public boolean canRender(IFeatureClass fc, IDisplay display) throws IOException, AutomationException {
if (fc.getShapeType() == esriGeometryType.esriGeometryPolygon)
return true;
else
return false;
}
// Could be used for query filter
public void prepareFilter(IFeatureClass fc, IQueryFilter qFilter)throws IOException, AutomationException { }
// How to render
public void draw(IFeatureCursor featureCursor, int drawPhase, IDisplay display, ITrackCancel trackCancel) throws IOException,AutomationException {
System.out.println("Hello, here I am");
try {
IFeature feature = featureCursor.nextFeature();
display.setSymbol(greenSymbol());
do{
display.drawPolygon(feature.getShape());
feature = featureCursor.nextFeature();
}while (feature != null);
System.out.println("Hello, here I was");
} catch (Exception e) {
System.out.println(e.getMessage());
}
return;
}
public ISymbol getSymbolByFeature(IFeature arg0) throws IOException,AutomationException {
return null;
}
public boolean isRenderPhase(int drawPhase) throws IOException,AutomationException {
if (drawPhase == esriDrawPhase.esriDPGeography) return true;
else return false;
}
public void setExclusionSetByRef(IFeatureIDSet featureIDSet)throws IOException, AutomationException { }
public void writeExternal(ObjectOutput out) throws IOException { }
public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException { }
}
... View more
07-17-2011
11:41 AM
|
0
|
2
|
616
|
POST
|
Hi Forum I have made a little edit utility for ArcMap. It works well, but about once a day ArcMap will close unexpectedly, leaving a message like the attached png. Different dll's like nt.dll, EditTools.dll and Geometry.dll experience uncaught Access Violation Errors. I am not sure if my utility is causing these errors, but they seem to occur more often, when this utility is used. One of the things I am not sure of is my use of ESRI's projection Engine. I followed the advices on this thread: Can I get the Geodesic Angle directly from projection Engine? and it does work. 1) I made a fairly simple class ProjectionEngineWrap as an excerpt from Richie Carmichael's example. But should I give it a GUID and find it with findExtension()? 2) Should I do something special in order to make it threadsafe? 3) My Class Edithelper uses an instance of ProjectionEngineWrap. When I am finished with the instance, is it sufficient, as I do, to call dispose() and set the member variable to null, or should I do something more? I am using ArcGis 9.3.1 and C# in Visual Studio I would be happy if someone could point me in the direction of more information. Regards Marianne B. Wiese
/* GEUS 2010
* Author: Marianne B. Wiese
*
* This Module uses the methods from Richie Carmichael's wrapper
* http://mrrichie.spaces.live.com/blog/cns!DD16C3F34F4D913E!1807.entry
*
* */
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace GEUS
{
public class ProjectionEngineWrap : IDisposable
{
private bool m_disposed = false;
private IntPtr m_pe = IntPtr.Zero;
private GeodesicDistance m_gd = null;
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllname);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32.dll")]
private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
private delegate void GeodesicDistance(
[In] double semiMajorAxis,
[In] double eccentricity,
[In] double longitude1,
[In] double latitude1,
[In] double longitude2,
[In] double latitude2,
[Out] out double distance,
[Out] out double azimuthForward,
[Out] out double azimuthBack);
public ProjectionEngineWrap()
{
string dll = getDesktopDll();
// Load Projection Engine
this.m_pe = ProjectionEngineWrap.LoadLibrary(dll);
if (this.m_pe == IntPtr.Zero)
throw new Win32Exception(Marshal.GetLastWin32Error());
// Get pointer to function call
IntPtr gd = ProjectionEngineWrap.GetProcAddress(this.m_pe, "pe_geodesic_distance");
if (gd == IntPtr.Zero) {
int err = Marshal.GetLastWin32Error();
this.Dispose();
throw new Win32Exception(err);
}
// Create delegate
this.m_gd = (GeodesicDistance)Marshal.GetDelegateForFunctionPointer(gd, typeof(GeodesicDistance));
}
~ProjectionEngineWrap() { this.Dispose(); }
public void Dispose() {
if (this.m_disposed) { return; }
if (this.m_pe != IntPtr.Zero)
{
// Release Memory
ProjectionEngineWrap.FreeLibrary(this.m_pe);
}
// Update flag.
this.m_disposed = true;
// No need to finalize
GC.SuppressFinalize(this);
}
/// <summary>
/// Returns the geodestic azimuth and distance between two geographic locations.
/// http://edndoc.esri.com/arcsde/9.3/api/capi/geometry/coordsys/pegeodesicdistance.htm
/// </summary>
/// <param name="semiMajorAxis">Semi Major Axis</param>
/// <param name="eccentricity">Globe Eccentricity</param>
/// <param name="longitude1">From Longitude (radians)</param>
/// <param name="latitude1">From Latitude (radians)</param>
/// <param name="longitude2">To Longitude (radians)</param>
/// <param name="latitude2">To Latitude (radians)</param>
/// <param name="distance">Returned Geodetic Distance</param>
/// <param name="azimuthForward">Returned Forward Azimuth (radians)</param>
/// <param name="azimuthBack">Returned Reverse Azimuth (radians)</param>
public void GetGeodesicDistance(
double semiMajorAxis,
double eccentricity,
double longitude1,
double latitude1,
double longitude2,
double latitude2,
out double distance,
out double azimuthForward,
out double azimuthBack)
{
this.m_gd(
semiMajorAxis,
eccentricity,
longitude1,
latitude1,
longitude2,
latitude2,
out distance,
out azimuthForward,
out azimuthBack);
}
private string getDesktopDll()
{
RegistryKey coreRuntime = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ESRI\CoreRuntime", false);
if (coreRuntime == null) { return null; }
object installDir = coreRuntime.GetValue("InstallDir", null);
coreRuntime.Close();
if (installDir == null) { return null; }
string folder = installDir.ToString();
string bin = Path.Combine(folder, "bin");
return Path.Combine(bin, "pe.dll");
}
}
}
private float getMeridianConvergence(IPoint p0)
{
// GRS_1980. From File: North American Datum 1983.prj
const double semiMajorAxis = 6378137;
// Eccentricity squared of the spheroid e^2 = 2f-f^2
// Calculated from flattening f = 1/298.257222101
// Inverse flattening from File: North American Datum 1983.prj
const double eccentricity = 0.00669438002298586;
if (peEngine == null)
peEngine = new ProjectionEngineWrap();
meridianConvergence = 0; // float
try
{
// p0's latlong koordinater
p0.Project(geographicSpatialRef);
p0.QueryCoords(out fromLong, out fromLat);
// Koordinater fra et punkt 100 m nord for p0 (kort nord)
p0.Project(map.SpatialReference);
p0.QueryCoords(out X, out Y);
p0.PutCoords(X, Y + 100);
p0.Project(geographicSpatialRef);
p0.QueryCoords(out toLong, out toLat);
// Sæt tilbage, så anchorpoint i onVertexAdded() ikke forskydes
p0.Project(map.SpatialReference);
p0.PutCoords(X, Y);
// Lokal meridiankonvergens fra ESRI's 'projektionsmaskine' bibliotek, pe.dll
peEngine.GetGeodesicDistance(semiMajorAxis,
eccentricity,
ToRadians(fromLong),
ToRadians(fromLat),
ToRadians(toLong),
ToRadians(toLat),
out distance,
out azimuthForward,
out azimuthBack);
meridianConvergence = 360 + (float)ToDegrees(azimuthForward);
if (meridianConvergence > 359)
meridianConvergence -= 360;
}
catch (Exception e)
{
MessageBox.Show("GEUS EditHelper getMeridianConvergence(): \n" + e.Message);
}
return meridianConvergence;
}
void EditHelper_OnStopEditing(bool save)
{
if (peEngine != null)
{
peEngine.Dispose();
peEngine = null;
}
}
... View more
10-15-2010
01:22 AM
|
0
|
0
|
2138
|
POST
|
Hi Kirk The "SCALE" fieldname can't be the problem here. I get the same error even if i deleted the scale field beforehand, and I comment out deleteField("SCALE"); AccessViolationException Message = "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Also, the first time I run the program it will delete the ANGLE - field and fail on SCALE-field. The next time I run the program it will tell me there is no ANGLE-field, delete the SCALE-field and fail on POLYGONID-field. And so on... For now, I will not use more time on this. (The next step would be to test the program on some other featureClass or to close and open the workspace between calls to deleteFields, I guess) I will delete those fields manually, letting my program start its work from there. Thanks for your try. Marianne
... View more
05-29-2010
09:02 AM
|
0
|
0
|
758
|
Online Status |
Offline
|
Date Last Visited |
07-07-2022
08:35 AM
|