I am trying to write an ArcPy script tool that will store a point object in a BLOB field that I have created. I don't know if that is even possible. If it is, how do I do it, and how can I then retrieve and update that point later? It is probably possible to do it through ArcObjects (which I would rather do), but I am restricted to an arcpy script tool by client specs. I am rather new at the arcpy thing (much more comfortable with ArcObjects).

I should ask: is there a way to access ArcObjects natively from within a script tool, like the ThisDocument hook that was available in VBA? If so, I could justify using ArcObjects, as long as I didn't have to go through comtypes (which is what I usually do with standalone Python automation scripts).

  • As far as I know, Python cannot access ArcObjects unless you're using IronPython, discussed in some detail here: gis.stackexchange.com/questions/7853/… – Nathanus Apr 5 '11 at 20:48
  • @Nathanus - Actually, there are a couple of ways to get full ArcObjects access from Python. Take a look at this post: http://gis.stackexchange.com/questions/5017... I use comtypes a lot, because I already know ArcObjects and Python well. I am just not a C/C++/.NET programmer. True, as discussed in the linked post, ctypes would be a cleaner and more Pythonic way to go, but I am simply not up to the programming required. – celticflute Apr 6 '11 at 3:08

One thing you could look at is Serialization of your shape object. This will allow you to pack the object containing your geometry into a byte array (sort of) and 'should' also allow you to store it in a BLOB field. This is untested though.

Look at Pickle for Serialization.

I hope this helps.

  • 1
    Thank you. This is indeed what needs to be done to prepare the object for storage; however, the problem it seems is that you can't avoid having to use ArcObjects to do the actual storage to (and retrieval from) the BLOB field. I use ArcObjects all the time from Python, but the whole idea behind this particular script was to have a tool script that could be distributed to users without dependencies on comtypes and ArcObjects. Oh well .. – celticflute Apr 6 '11 at 3:20

Forget about going directly to ArcObjects from Python, it's not worth the trouble. There are other better ways.

For what you want to do there are two main issues:

  1. You'll have to figure out some way of serializing the geometry.
  2. ArcPy doesn't support reading or writing blob fields at 10.0.

No. 1 is perfectly doable and you have plenty of options: roll your own, JSON, GeoJSON, ... I'm not sure how Pickle likes the arcpy geometry types, but it's worth a shot too.

No. 2 is certainly fixable as well. You can go outside of arcpy and work with a native Python database driver for whatever RDBMS you're using (complicated if you need to support .mdb or file geodatabases). Another option is writing your own custom gp tools in ArcObjects for reading and writing blobs: implement IGPFunction2 among others and use IMemoryBlobStream for working with the blob field. Really not hard if you're familiar with ArcObjects. The developer doc has a nice walk-through of building custom gp tools: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/0001/00010000049w000000.htm

If you really want ArcObjects then the custom gp tool option opens up pretty much anything. I'd encourage you to only do that in exceptional cases though (as with the lack of support for blobs in arcpy). If you can get by with pure Python + arcpy, you'll be in a much better long-term position for maintaining your code and upgrading it when new arcpy functionality becomes available in newer versions.

  • Thank you, Philip. For No. 1, Pickle seems to work fine. The problem is the lack of BLOB support under arcpy, and I am indeed working in file geodatabases. So, a custom gp tool would be great ... if I had the .NET skills to do it. I used to use VB6/ArcObjects a lot, but .NET is pretty far gone from VB6 these days. I will, perhaps, do this for my own edification, but the client has neither the time nor the money to support the effort at this time. BTW, what specifically is the "developer doc" with the sample that you mention above. Perhaps you could link it in your above answer. – celticflute Apr 6 '11 at 12:31
  • @celticflute See updated link in my answer. You can implement a custom gp tool with VB6 still, although VB.NET (or C#, or whatever) is the better choice simply for reasons of official support. – Philip Apr 9 '11 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.