|
POST
|
You could use the modern format() unction for strings to more easily assemble SQL strings from variables. This is easy to then just use single quotes around SQL string expressions. If you want to enclose sql variable names in double quotes, use treble quotes to enclose the expression. You don't need to use double quotes if the variable names are valid names, no spaces and not reserved words and are not using Microsoft Access. Who uses personal geodatabases any more? I don't bother with the field delimeter function personally because I know my target database is not Access. If you always use treble quotes it is nicely highlighted in my IDE (pyscripter) differently from other strings. Note that the format statement allows multiple references to one variable, reducing duplication. It is also easier to strip unicode prefixes from strings in the function using a encode function if necessary. The format expression is much easier to read because it is closer to the literal string and is easier to debug by removing most of the quote characters. sqlprikaz='"Layer" LIKE ' + "'%PLOCH%'" and "Layer" <> "%_"
layer = 'Layer_name'
search_string = 'PLOCH'
sqlprikaz = """{0} LIKE '%{1}%' AND {0} NOT LIKE '%_'""".format(layer,search_string)
print sqlprikaz
... View more
02-01-2016
12:49 PM
|
0
|
0
|
6164
|
|
BLOG
|
Ingenious! I have huge headers as comments which I could convert to a triple quoted string to document the script method.
... View more
09-10-2015
03:46 PM
|
0
|
0
|
437
|
|
POST
|
Until it was removed at 10.x! I see it has returned to update the in-memory reference after a system copy so maybe it is just a null-op if the paths have not changed? It doesn't mention closing any open table locks so my assumption is that it doesn't. It is certainly helpful to keep the Catalog up to date with the windows file system when using file geodatabases, which may lag due to various remote services, buffers, file lock indicators (which are just a temporary file) cleanup not kicking in fast enough during running a script. Bruce can you help us there?
... View more
08-20-2015
04:32 PM
|
0
|
1
|
2975
|
|
POST
|
You might be thinking of the tool in ArcCatalog for removing locks on multiuser enterprise databases such as SqlServer or Oracle. This is a different (and much easier problem) because the database is managing the locks, not Windoze. But there is no python scripting tool, it is just a GUI in ArcCatalog.
... View more
08-20-2015
03:03 PM
|
0
|
4
|
2975
|
|
POST
|
psutil has changed the function names in my download. p.name is now a function p.name() and p.get_open_files() is now p.open_files() documentation This will work for processes on your machine, but I don't know how to close files open across a network. This could happen if someone goes home with ArcMap open and their screen saver on. Anyone with ideas?
... View more
08-18-2015
10:12 PM
|
1
|
8
|
2976
|
|
POST
|
I would not use Describe in this way to find the number of features on an intersect selection any more. This is a desperate workaround using old technology that is very clumsy and slow compared to using geometry objects. I know we all used to use FIDSETs in scripts because there was no other way, but now there are much better ways. Never use buffer. It is a redundant step that was only put in training courses to illustrate a spatial extent. In real life things are not well modelled by a buffer, floods follow contours, not a buffered centrelines, pollution creates a plume, not a circular area around a pollution point source. You can always use a selection radius around a point without having to waste computing power creating a separate featureclass. Even if you do need a polygon to say cut up another polygon into parts you can create a polygon geometry from a point, instead of a polygon featureclass. Use geometry objects. These are relatively new at 10.x and save a huge amount of processing to temporary disk based featureclasses. It is easy to turn featureclasses into lists of geometry objects that can be used instead of a featureclass with spatial operators. Geometry objects also have spatial operators so you can compare pairs directly. The help has some excellent diagrams for the spatial operators. The operators are extensive and cover every case of possible overlaps. Instead of looking for a count after a timewasting SelectByLocation() you can just ask if geom1.crosses(geom2): It is fast because it is all in memory and is much easier to program. No need to run Describe() at all.
... View more
06-11-2015
03:42 PM
|
1
|
1
|
516
|
|
POST
|
Add Joins? You must be only using a sample. That would fail for 2 million records in my experience. The reason I went back to the overlay operations is because partitioning has been implemented. Before that it wasn't an option. Since merge is not part of the partition function I wonder how long it might take. My complaint is why do I have to go to all this trouble since the help clearly says that layers are a valid input. This thread is to warn that they are not. Making a fieldmap is very tricky if I want to automate it because I would need to automate building the field maps. My script is already complicated. It has gone from a single line Intersect tool to 140 odd lines and its not a general tool even then.
... View more
05-05-2015
10:38 PM
|
0
|
1
|
2220
|
|
POST
|
Thanks for the concern. I am certain that its a bug, and I am just grumpy and want to alert others when they hit the same thing. Suppose I have an address point layer and I want to assign a suburb and postcode from some polygon layers. D:/data/NZFireService/nzsuburb.gdb/nz_localities Keep fields: ['suburb_4th', 'major_name'] Fieldinfo: nz_localities SUBURB_4TH SUBURB_4TH VISIBLE #;MAJOR_NAME MAJOR_NAME VISIBLE # List fields: [u'OBJECTID', u'Shape', u'POSTCODE', u'ROUND_NAME', u'MAIL_TOWN', u'Shape_Length', u'Shape_Area'] D:/data/NZPost/PostCode/PNF.gdb/PostCode Keep fields: ['postcode'] Fieldinfo: PostCode POSTCODE POSTCODE VISIBLE # List fields: [u'OBJECTID', u'Shape', u'POSTCODE', u'ROUND_NAME', u'MAIL_TOWN', u'Shape_Length', u'Shape_Area'] Processing overlays ... ['e:/crs/presentgdb/roadadd.gdb/addhist', 'lay_nz_localities', 'lay_PostCode'] 0:00:51.979000 [u'OBJECTID', u'SHAPE', u'FID_addhist', u'sad_id', u'house_number', u'rna_id', u'range_high', u'rcl_id', u'et_created', u'sufi', u'unofficial_flag', u'range_low', u'et_edited', u'status', u'roadtype', u'location', u'status_name', u'road_name', u'road_type', u'road_suffix', u'full_road_name', u'FID_PostCode', u'POSTCODE', u'ROUND_NAME', u'MAIL_TOWN', u'FID_PostCode_1', u'POSTCODE_1', u'ROUND_NAME_1', u'MAIL_TOWN_1'] The result is - No suburbs! Just the postcode fields twice. If I have three polygon layers they are added 3 times and so on. My workaround was to use full featureclass paths with ALL and run a couple of list comprehensions afterwards to generate a large list of fields to delete. The time ballooned out to 2 hours. I then ran the new AlterField command that lets me rename a field and the alias. The fieldInfo object appears to set a new alias but does not.
... View more
05-05-2015
08:31 PM
|
0
|
3
|
2220
|
|
POST
|
I prototyped a tool in ArcMap using a multiple intersect of a point featureclass with several polygon layers. Basically a multiple point-in-polygon operation. It is much faster now that partitioning is automatically invoked at 10.3 (or some earlier version). To avoid all the extra polygon fields I turn off all the additional fields in the layer properties. I do get extra FID_<fc> fields that I did not ask for but these are easy enough to delete with a list = [f.name for f in arcpy.Listfields(fc,'FID_*')] in the delete tool. But now I want to put this in a script... I take the tool as a snippet and put it in a stand-alone script. I need to define the layers, which I do using arcpy.management.MakeFeatureLayer() adding a Fieldinfo() object with all the fields hidden or visible. (the opposite of visible is..?) Output: the overlay produces a point layer BUT last polygon layer is repeated n times, the other (n-1) layers are missing, the process takes far too short a time and the result is nonsense, but with no error messages. I was hoping to use the rename facility in fieldinfo (it does not rename the alias so It needs an extra step) but since nothing works that was too much of a stretch. ie why got to the trouble of using fieldInfo anyway. Intersect will properly populate FID_<fc_name> fields if I use the option 'ONLY_FID' on featureclasses, but then I have the tedious task of adding the fields and populating them myself. JoinField is not suitable for 2 million records. Maye MakeSQLQuery would be better if I had to go down that route, add indexes, build a complex sql expression. Oh, that won't work, because all the tables have to be in the same database, unlike spatialite. The only workaround I can think of is to leave ALL the fields on with a list of featureclasses, not layers, and then run a humongous delete function afterwards instead of a tidy fieldinfo beforehand.
... View more
05-05-2015
03:51 PM
|
0
|
5
|
6280
|
|
POST
|
What a wonderful insight to this problem that has bugged me for years. I avoid all exported joins because of the nulls, and I could never work out why. All I now have to do is check for the existence of a FID! My workaround is to create a python dictionary and run a cursor which is actually faster. Might I also suggest SCHEMA.INI on your text files before you import them with TabletoTable? This is a standard Microsoft function that is used by ArcGIS to add a correct database schema to a CSV or TXT file. This avoids the dreaded 255 char wide fields, and properly defines integers instead of floats. All this will make joins more successful when it is finally in a geodatabase with a proper ObjectID.
... View more
04-30-2015
02:37 PM
|
2
|
1
|
2284
|
|
POST
|
Use the python module matplotlib included in the ArcGIS install as standard. You might need to download the manual separately.
... View more
04-22-2015
04:18 PM
|
0
|
0
|
880
|
|
POST
|
04-22-2015
03:44 PM
|
0
|
0
|
1411
|