Select to view content in your preferred language

arcpy.Warp_management not performing as expected

3346
4
Jump to solution
07-03-2016 11:52 PM
AnthonyCheesman1
Frequent Contributor

Hi - I'm unsure whether this is a Python question or a geoprocessing question. I'll post it here and see how we go.

I am trying to use the 'warp' function in a rather novel way. I have a heap of (~800) individual QR codes, which I'd like to georeference so that they can be displayed as map features.

The QR codes are all the same size and I can use the same reference points, whereas the location to georeference the features 'to' (ie where I want them to sit on the map) will change from code to code. This location is determined by the location of a given point.

I've cobbled together a script to iterate through the codes, and the script runs correctly, but the output features aren't georeferenced at all.

I've also tried georeferencing a single feature via the Toolbox, but that doesn't perform as expected either.

The script (snippet of) I'm using is below:

ls_inputs = os.listdir(ws_inputs)

for i in ls_inputs:

    if i[0:-4] in dict_mapcentroid:

        print "Working on", i

        input = os.path.join(ws_inputs, i)

        cent_x = dict_mapcentroid[i[0:-4]][0]

        cent_y = dict_mapcentroid[i[0:-4]][1]

        target_pt = "'11.5 -158.5';'158.5 -11.5'"

        source_pt = "'%s %s';'%s %s'" % (cent_x - 1750, cent_y - 1750, cent_x + 1750, cent_y + 1750)

        output = os.path.join(ws_outputs, "georef_%s" % i)

        arcpy.Warp_management(input, source_pt, target_pt, output, "POLYORDER1")

    else:

        print "Fail on", i

(dict_mapcentroid refers to a dictionary with the feature name as key, and the coordinates of the centroid as a [x,y] list)

(the reference points are bottom left and top right, the +/- 1750 allow for the scaling of the feature to appear 3 x 3cm at 1:250K)

Can anyone shed any light on why this wouldn't be working - or am I simply trying to use a tool in a manner in which it was not intended?

Thanks

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

It is strongly suggested to use more than the minimum number of links.

I would go wild and whip in a few more... it is the placement that is important as well... which may seem obvious, but based on lab assignments I have had to deal with... less so than one would imagine

View solution in original post

4 Replies
DanPatterson_Retired
MVP Emeritus

The help link has a reference to the minimum number of points required to 'warp' a raster to a new location.  You have one, you need 6 for a first order.  So the direct answer to your question is, you are using it for the wrong purpose

Warp—Help | ArcGIS for Desktop

There is

Shift—Help | ArcGIS for Desktop

which will get a raster to a new location, however what you are moving would need a known cell size to make it useful.

So if what you are moving, in the form of a raster, has a known cell size and just needs to be moved, you 'shift' it, if there is distortion or the cell size is unknown or just a big picture, you need to warp it.  If it is vector data, you need to use the Spatial Adjustment tool

AnthonyCheesman1
Frequent Contributor

Thanks Dan for the information and your prompt reply (as always).

The data I am attempting to use is in .png format and does need to be scaled as well as moved, hence the warp function being used.

When you say 6 control points - do you mean 3 on the source and 3 on the target? I'm using 2 (or 4, depending on the interpretation). The (p+1)(p+2)/2 formula on the help page tells me 3 points for a 1st order polynomial, so I'll give that a crack tomorrow.

Hopefully an extra control point fixes this!

0 Kudos
DanPatterson_Retired
MVP Emeritus

It is strongly suggested to use more than the minimum number of links.

I would go wild and whip in a few more... it is the placement that is important as well... which may seem obvious, but based on lab assignments I have had to deal with... less so than one would imagine

AnthonyCheesman1
Frequent Contributor

Success! 4 reference points has solved the problem.

Thanks for the help Dan.

0 Kudos