Re: Fw: [Zope] problem with the shapelib module.. help
Allen Huang wrote at 2006-12-23 22:27 -0800: >I've being trying different things for the pass day > >1. I put the shapefile directly in the Extensions with the external method and >it work fine >import shapelib, dbflib >def readshp(): >shp = shapelib.ShapeFile('taiwan1.shp') This means, that "ShapeFile" is Zope unaware and will interpret its argument as a filepath (maybe relative to the current working directory). The above will work when there is a 'taiwan1.shp' file in the directory of the so called "INSTANCE_HOME" (which is Zope's usual current working directory). In an "External Method" (or other trusted code), you can use Python's file operations to write files. E.g. you can create 'taivan1.shp' as follows: f = open('taiwan1.shp', 'wb') f.write(file_content) f.close() Be warned however, that Zope is a multithread application. Therefore, it is dangerous to use fixed file names (one thread may overwrite the file created in a different thread). You probably would want to have the files created with functions you find in Python's "tempfile" module. In case the file you want to precess it a Zope "File" object "f" (a file in the ZODB), then, you can access its data via "str(f.data)" (and write this to a file on the file system). In case, the file you want to precess is updated via a POST request, it will be turned into a "ZPublisher.HTTPRequest.FileUpload" objects which behaves like a Python file object (with some additional methods and attributes). Especially, you can use "f.read()" to read its content. -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Fw: [Zope] problem with the shapelib module.. help
Thanks a lot for replying... I still a newbie at this ... in order for shapelib to read shapefile, you need a set of three files(.shp, .shx, .dbf). so, if I have to download this to a temp location into my computer filesystem, could you show me how this is done? - Original Message From: Andreas Jung <[EMAIL PROTECTED]> To: Allen Huang <[EMAIL PROTECTED]>; Zope Sent: Sunday, December 24, 2006 2:47:52 PM Subject: Re: Fw: [Zope] problem with the shapelib module.. help -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 - --On 23. Dezember 2006 22:27:29 -0800 Allen Huang <[EMAIL PROTECTED]> wrote: > > 2. but when I save the shapefiles (taiwan1.shp, taiwan1.shx, taiwan1.dbf) > into zope and call it using dtml it return the same error message. > import shapelib, dbflib > def readshp(filename): > shp = shapelib.ShapeFile(filename) > return shp.info() > > and in zope > > or > http://localhost/pytest/taiwan1.shp')";> No idea what shapelib is doing but reading a file from the locale filesystem as it seems to work from an external method is *different* from a accessing content that is stored within the ZODB. I really wonder why you think it would work the same way? The hierarchical object storage of Zope looks similar to a filesystem but it is not a filesystem and the Python APIs for accessing filesystems don't apply. We have no idea what the ShapeFile constructors expects as data. If it expects a filename of a file within the filesystem then you must obtain the content of your data stored within the ZODB, create a temporary file and call the constructor as you did within your external method. Possibly the constructor accepts the data directly as *string*..in this case this would make things a bit easier. But it is up to *you* to check the Shapelib API and take appropriate action. - -aj -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (Darwin) iD8DBQFFjiKYCJIWIbr9KYwRAk0oAKCSyEo5ykswElgi9jFGWf89NthzmwCfRvEM nSMyeIu/cK7NpecUlof2BR8= =B0Mw -END PGP SIGNATURE- __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: Fw: [Zope] problem with the shapelib module.. help
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 - --On 23. Dezember 2006 22:27:29 -0800 Allen Huang <[EMAIL PROTECTED]> wrote: > > 2. but when I save the shapefiles (taiwan1.shp, taiwan1.shx, taiwan1.dbf) > into zope and call it using dtml it return the same error message. > import shapelib, dbflib > def readshp(filename): > shp = shapelib.ShapeFile(filename) > return shp.info() > > and in zope > > or > http://localhost/pytest/taiwan1.shp')"> No idea what shapelib is doing but reading a file from the locale filesystem as it seems to work from an external method is *different* from a accessing content that is stored within the ZODB. I really wonder why you think it would work the same way? The hierarchical object storage of Zope looks similar to a filesystem but it is not a filesystem and the Python APIs for accessing filesystems don't apply. We have no idea what the ShapeFile constructors expects as data. If it expects a filename of a file within the filesystem then you must obtain the content of your data stored within the ZODB, create a temporary file and call the constructor as you did within your external method. Possibly the constructor accepts the data directly as *string*..in this case this would make things a bit easier. But it is up to *you* to check the Shapelib API and take appropriate action. - -aj -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (Darwin) iD8DBQFFjiKYCJIWIbr9KYwRAk0oAKCSyEo5ykswElgi9jFGWf89NthzmwCfRvEM nSMyeIu/cK7NpecUlof2BR8= =B0Mw -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Fw: [Zope] problem with the shapelib module.. help
shapelib still didn't work for me.. help I've being trying different things for the pass day 1. I put the shapefile directly in the Extensions with the external method and it work fine import shapelib, dbflib def readshp(): shp = shapelib.ShapeFile('taiwan1.shp') return shp.info() and in zope or http://localhost/pytest/taiwan1.shp')"> The error message are 1. in "Run Zope in Console" Exception exceptions.AttributeError:"ShapeFile instance has no attribute 'thisown'" in ignored 2. in web browser Site Error An error was encountered while publishing this resource. Error Type: IOError Error Value: new_ShapeFile failed is there something wrong with how I constructed it? Do I need to do something before hand? 3. in error_log Traceback (innermost last): Module ZPublisher.Publish, line 115, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 41, in call_object Module OFS.DTMLMethod, line 143, in __call__ - - URL: http://localhost/testPython/test/manage_main - Physical Path: /testPython/test Module DocumentTemplate.DT_String, line 476, in __call__ Module DocumentTemplate.DT_Util, line 196, in eval - __traceback_info__: readshp Module , line 1, in Module Products.ExternalMethod.ExternalMethod, line 231, in __call__ - __traceback_info__: (('http://localhost/testPython/taiwan1.shp',), {}, None) Module C:\web\ZopeInstance\Extensions\shapetools.py, line 4, in readshp Module shapelib, line 44, in __init__ IOError: new_ShapeFile failed - Forwarded Message From: Dieter Maurer <[EMAIL PROTECTED]> To: Allen Huang <[EMAIL PROTECTED]> Cc: Zope Sent: Saturday, December 23, 2006 3:52:53 AM Subject: Re: [Zope] problem with the shapelib module.. help Allen Huang wrote at 2006-12-21 23:23 -0800: >I want to do some mapping application with zope.. but I have run into this >problem over and over.. > >in "Run Zope in Console" >Exception exceptions.AttributeError:"ShapeFile instance has no attribute >'thisown'" in ignored Hmm. I doubt that you have really seen this text. There should be something in between the "in" and the "ignored". It is *vital* that you are as precise as possible in your problem reports... Python emits messages of the kind above in some (rare) situations, e.g. when exceptions occur in destructors. The exception above seems to have been raised in such a situation. The missing thing betwenn "in" and "ignored" should tell us which situation this was. It tells you that something tries to access the attribute "thisown" on a "ShapeFile" instance but this does not have the attribute. > >in web browser >Site Error >An error was encountered while publishing this resource. >Error Type: IOError >Error Value: new_ShapeFile failed Another tip for the future. When you report problems, you need to include full error information. Beside the "Error Type" and "Error Value" above, this also includes the traceback. You find all this information in the "error_log" object in Zope's "Root Folder" (Management Interface). -- Dieter __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] problem with the shapelib module.. help
Please stay on the mailing list. Readded ... Allen Huang wrote at 2006-12-22 19:47 -0800: > ... >is there something wrong with how I constructed it? It is still something wrong with the way you report problems. See below in my quoted message from yesterday. And be aware that we might get a bit angry when you do not read our messages carefully. > >- Original Message >From: Dieter Maurer <[EMAIL PROTECTED]> >To: Allen Huang <[EMAIL PROTECTED]> >Cc: Zope >Sent: Saturday, December 23, 2006 3:52:53 AM >Subject: Re: [Zope] problem with the shapelib module.. help > >Another tip for the future. When you report problems, you need >to include full error information. Beside the "Error Type" and >"Error Value" above, this also includes the traceback. >You find all this information in the "error_log" object in >Zope's "Root Folder" (Management Interface). -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] problem with the shapelib module.. help
Allen Huang wrote at 2006-12-21 23:23 -0800: >I want to do some mapping application with zope.. but I have run into this >problem over and over.. > >in "Run Zope in Console" >Exception exceptions.AttributeError:"ShapeFile instance has no attribute >'thisown'" in ignored Hmm. I doubt that you have really seen this text. There should be something in between the "in" and the "ignored". It is *vital* that you are as precise as possible in your problem reports... Python emits messages of the kind above in some (rare) situations, e.g. when exceptions occur in destructors. The exception above seems to have been raised in such a situation. The missing thing betwenn "in" and "ignored" should tell us which situation this was. It tells you that something tries to access the attribute "thisown" on a "ShapeFile" instance but this does not have the attribute. > >in web browser >Site Error >An error was encountered while publishing this resource. >Error Type: IOError >Error Value: new_ShapeFile failed Another tip for the future. When you report problems, you need to include full error information. Beside the "Error Type" and "Error Value" above, this also includes the traceback. You find all this information in the "error_log" object in Zope's "Root Folder" (Management Interface). -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] problem with the shapelib module.. help
> I change some setting to my runzope.bat because I want zope to use > python2.4.4 instead of the build 2.3.5 Don't do that. If you need python2.4 then use newer Zope version that uses 2.4 eg. Zope2.9, Zope2.10. > import shapelib, dbflib > def testShapeLib(self): > f1 = shapelib.ShapeFile('C:\\web\\ZopeInstance\\taipei.shp') Is this working without Zope? -- Maciej Wisniowski ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] problem with the shapelib module.. help
I want to do some mapping application with zope.. but I have run into this problem over and over.. in "Run Zope in Console" Exception exceptions.AttributeError:"ShapeFile instance has no attribute 'thisown'" in ignored in web browser Site Error An error was encountered while publishing this resource. Error Type: IOError Error Value: new_ShapeFile failed I change some setting to my runzope.bat because I want zope to use python2.4.4 instead of the build 2.3.5 because I have install shapelib module(pyshapelib-0.3.win32-py2.4) which is the module I want to use for the import of my external methods. The runzope.bat looks like this: @set PYTHON=C:\Python24\python.exe @set ZOPE_HOME=C:\web\Zope\Zope @set INSTANCE_HOME=C:\web\ZopeInstance @set SOFTWARE_HOME=C:\web\Zope\Zope\lib\python @set CONFIG_FILE=C:\web\ZopeInstance\etc\zope.conf @set PYTHONPATH=C:\Python24\Lib;%INSTANCE_HOME%\lib\python;%SOFTWARE_HOME%;%PYTHONPATH% @set ZOPE_RUN=%SOFTWARE_HOME%\Zope2\Startup\run.py "%PYTHON%" "%ZOPE_RUN%" -C "%CONFIG_FILE%" %1 %2 %3 %4 %5 %6 %7 I made a very short python external method to test the shapelib module import shapelib, dbflib def testShapeLib(self): f1 = shapelib.ShapeFile('C:\\web\\ZopeInstance\\taipei.shp') but all I get out of it is the above two errors anyone have any idea what i'm do wrong with my settings or my code? any thought? __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )