CreateRandomPoints_management creates empty feature class

1673
10
07-22-2013 07:07 AM
DominikFechter
New Contributor
Hi guys,
I'm totally lost and on the verge of a mental breakdown. I'm trying to write a script for an automatic CostPath analysis and I'm getting very weird results and errors. Basicly what I want is this:

I'm creating a CostDistance Raster dataset and the backlink set by multiplying different Raster Datasets with randomly generated numbers and using a polygon-feature class as the starting point. so far so good. Then I create four random points, constraint by four polygones to act as the destination. When I start the CostPath analysis, I get this error:

Traceback (most recent call last):
  File "E:\My Dropbox\Diss\Python Workspace\GIS Tutorial\src\test_rand.py", line 216, in <module>
    outCostPathFrankreich = CostPath(PFrankreich, outCostDist, outBkLinkRaster, "BEST_SINGLE", "FID")
  File "C:\Programme\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 693, in CostPath
    destination_field)
  File "C:\Programme\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Utils.py", line 47, in swapper
    result = wrapper(*args, **kwargs)
  File "C:\Programme\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 686, in wrapper
    destination_field)
  File "C:\Programme\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in <lambda>
    return lambda *args: val(*gp_fixargs(args))
arcgisscripting.ExecuteError: ERROR 010045: COSTPATH: The number of FROM cells is 0.
ERROR 010067: Error in executing grid expression.

Funny thing: When I look in my folder, there are four point features created, each with a point within my constraining feature class. So the points exist, but is does not work...

here are some code snippets that may help to understand the mess I made:
I dont post all the code to keep it small, if you need it, then please ask!


import sys
sys.path.append("C:/Programme/ArcGIS/Desktop10.0/arcpy/arcpy")

import random
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.env.overwriteOutput = True

arcpy.CheckOutExtension("Spatial")


#load constraining feature
ZielFrankreich = "E:/CORINE/CP_Paper3/Auswertung/basedata.gdb/FrancePointBuffer"

#create the random point
PFrankreich= arcpy.CreateRandomPoints_management("E:/CORINE/CP_Paper3/Auswertung", "randFrankreich", ZielFrankreich, "", 1)

#CostPath analysis, outCostDist, outBkLinkRaster have already been created, but to keep the codeblock as small as possible i dondt post it 
outCostPathFrankreich = CostPath(PFrankreich, outCostDist, outBkLinkRaster, "BEST_SINGLE", "FID")



If anyone has any idea that would be great. As I said, I'm so completly frustrated.... If you need any additional information, please ask.

Cheers, thanks a lot in advance,

Dominik
Tags (2)
0 Kudos
10 Replies
RhettZufelt
MVP Frequent Contributor
Without the other code, hard to tell what you are loading as your "polygon" layer, but I see the cost tools do not support feature classes.  Only raster and feature layers.

Are you running MakeFeatureLayer on your polygon before you use it as input to your script?

R_
0 Kudos
DominikFechter
New Contributor
Hi rzufelt,
thanks for your reply. I use polygones at two points:
1. to set the starting point for the CostDistance Analysis
2. as a constraining feature class for the creation of the random points

I didnt apply "MakeFeatureLayer on it, will try that tomorrow.

What is very strange, when I make the analysis by hand, i.e. use alle the tools one after another from the toolbox, then its working....

Cheers, will post if you saved me from going crazy 😉
If anyone else has any suggestions, they are still very very appreciated!

Dominik
0 Kudos
RhettZufelt
MVP Frequent Contributor
If you mean it runs "inside" of Arc, but not as stand alone, would really suspect it is related to feature layers.

ArcGIS will on-the-fly create the feature layers for tools that require it for input, silently (if running within Arc).  If you pick from the drop-down list, you never know if you are getting the layer or feature class itself.

The help on the create random points is not quite right, as it says Random points will be generated inside or along the features in this feature class. The constraining feature class can be point, multipoint, line, or polygon. Yet, immediatly next to it, says Data Type = Feature LAYER????  (what is it, can't be both)

The cost distance/path both say they need feature layer.

Hope this gets you going,

R_
0 Kudos
DominikFechter
New Contributor
Hi rzufelt,
Thanks again a lot! This makes (in a very weird way) sense, I'll try it tomorrow when I'm in the office. If this is it, you've earned a big aknowledgment in my thesis 😄

I'll report if this was the case.

Have good night,

Dominik
0 Kudos
DominikFechter
New Contributor
Well, I tried and failed 😄 I used the MakeFeatureLayer command on all shapefiles which are used in functions which require a feature layer... but still no luck.

I still get the same error:

arcgisscripting.ExecuteError: ERROR 010045: COSTPATH: The number of FROM cells is 0.
ERROR 010067: Error in executing grid expression.
Failed to execute (CostPath).

It's so annoying, the layerfile exists, the point exists, and when I use the tools from the toolbox in arcGIS step by step it works, but not in the script itself... And since I have to do around 10.000 CostPath analysis, thats not really an option....

any other ideas?

Still hoping for a miracle 😄

Dominik
0 Kudos
RhettZufelt
MVP Frequent Contributor
that's too bad, was hoping that would solve your issue.

Since it is working in the tool(s), I'm going to have assume you have seen this: http://resources.arcgis.com/en/help/main/10.1/index.html#//00vq0000000n010045 and ensured you data meets these requirements.

   Description
The input that identifies those cells from which the least-cost path is determined does not contain any valid values. If the input is a raster, it should consist of cells that have valid values (zero is a valid value), and the remaining cells must be assigned NoData.

Solution
Ensure that the raster you specify as the destination dataset has some cells with a valid value (not NoData). Check the documentation for Cost Path for further information.


You say it works "tool by tool", have you created a new model in ArcMap, then load each tool into that.  Once you get it to run in the model, you can export to python script.  Arc is not the "best" python code writer around, but you might see something in the exported code that gives a clue.

R_
0 Kudos
DominikFechter
New Contributor
Hi rzufelt,
The idea of building it up in the model builder and then export to a python script is interesting, I'll have a look at that tomorrow. I posted the code in another post, since i got another error message, saying that the "VAT will not be built". Maybe you could have a look at my code here:

http://forums.arcgis.com/threads/89042-CostPath-All-cells-in-grid-have-NODATA-value.-VAT-will-not-be....

I'm sorry for double posting, but i thought the original title of the thread could be missleading with the new error message.

I really appreciate all you're doing so far!!!!!

Thanks a lot,

Dominik
0 Kudos
DominikFechter
New Contributor
Problem seems to be solved. The reason was this:
Somehow the extent of the soure layer for the costdistance analysis was way smaller, leading to a costdistance and backlink layer, which were also smaller. In the following CostPath analysis the destination points were out of bound, thus leading to the error message "ERROR 010045: COSTPATH: The number of FROM cells is 0." I fixed the extent of the source layer for the costdistance analysis and it worked.

I think that it worked within ArcGIS, because the environment settings were not "union of input". Instead it was set to a fixed processing extent, thus not creating the problem within ArcGIS.

I used your tip of recreating the script in the model builder and then exporting it to a python script. There I saw, that with my script everything was right, so it had to be something else. Funny thing: When exporting it to a python script, it uses the ArcGIS 9.3 syntax....

So thank you very much rzufelt for your time, I really appreciated it and it helped me through the worst part 😄

Cheers, this night I get a good sleep 😄

Dominik
0 Kudos
RhettZufelt
MVP Frequent Contributor
Good to see you got it working. 

These get pretty difficult to debug the code when it's not the code causing the issue :rolleyes:

You say it is exporting in 9.3 syntax?  Do you mean that it is using the gp. instead of arcpy.?  What version you exporting it from?

I have not noticed this from my 10.0 and 10.1 box, but maybe I'm just not that familiar with the 9.3 syntax.  All mine export with arcpy though.

R_
0 Kudos