POST
|
Hi, Have you resolved your problem? If not, try to change your scratch folder to a different place on Desktop when running your script tool. sometimes the default folder in the User directory has permission issue. You can also use model tool, but I am not 100% sure if it works if you are using web app as Client. Give it a try anyway. You can use Calculate Value with absolute path (String data type) of the shape file as the input. Then use Copy Feature to copy the input file so Server will save the uploaded input shape file in the scratch gdb, and finally do the Buffer or any other Analysis with the uploaded file. I attached two gpk files for your reference - calcbuffer100.gpk (for 10.0 Server) and calcbuffer101.gpk (For 10.1 Server). Both models are almost the same, except in 10.1 model you have to set the output of Calculate Value as an output parameter, otherwise you won't get the input shape on the server. I have to figured out if this is a bug or as design. Let me know if this helps. Best, Shing Many thanks for your sincerely helps, but I didn't see any attachment. Where is your attachments??
... View more
02-27-2013
06:36 PM
|
0
|
0
|
874
|
POST
|
I,m looking for a script that can unzip a zipped shapefile and rename it to a new name. Problem: The default unzip.py just unzip a zipped file and don't change it's name. This restriction cause all clients have to rename thier shapefiles like my predefined name. For example If my shapefile's name is spatial.shp and I zipped it for running my model locally, my clients should change thier shape files to spatial.shp Regards
... View more
02-26-2013
06:41 AM
|
0
|
0
|
1574
|
POST
|
Hi I did it, But it return "Invalid syntax error"!!! There is not person that help me??????????????????????:rolleyes:
... View more
02-26-2013
03:40 AM
|
0
|
0
|
320
|
POST
|
It is pretty simple at this point. You just need to make sure your indentation is correct on those lines that I posted last. Delete the white space before each line so they are not indented and then tab each line over 1 time. The only exception is "except Exception as e:": should not be indented at all. Hi I did it, But model return "Invalid syntax error". That is pretty simple for you but not for me.
... View more
02-26-2013
03:32 AM
|
0
|
0
|
320
|
POST
|
The last few statements you have a incorrect. You need to use with the appropriate indentation.
# Process: Append
arcpy.Append_management(shpPath, WildFire_Table_Target, "NO_TEST", fieldmappings)
except Exception as e:
print e.message
arcpy.AddError(e.message) Hi I tested your code, but it return this error: IndentationError: unindent does not match any outer indentation level (import_zip_91.py, line 40) What is appropriate indentation? Please help me more. Is it possible to send me your model or your code? Regards
... View more
02-25-2013
07:48 AM
|
0
|
0
|
520
|
POST
|
You are going to have to post your code to this thread using code blocks. Without that I will not be able to properly view your code with the correct indenting. I attached pyton script. please help me.
... View more
02-22-2013
08:26 PM
|
0
|
0
|
520
|
POST
|
Honestly it is probably just an issue with the indentation due to copying and pasting. I would just go though and make sure everything is indented properly. Using a program like notepad++ will make it easier to spot issues. When I copied my code below into NP++ you can see that line is indented too much as well as 2 other below it. Just delete the white space before that following 3 lines and tab them each over 1 time. arcpy.Append_management(shpPath, WildFire_Table_Target, "NO_TEST", fieldmappings) print e.message arcpy.AddError(e.message) I changed it with your solution and it return this error: SyntaxError: invalid syntax This is my new code: import arcpy, os, zipfile infile = arcpy.GetParameterAsText(0) outpath, outfileext = os.path.splitext(infile) filename = outpath.split('\\')[-1] try: # unzip file fireZip = zipfile.ZipFile(infile, 'r') fireZip.extractall(outpath) fireZip.close() shpPath = outpath + "\\" + filename + ".shp" arcpy.AddMessage("Finished unzipping file.") # Local variables: WildFire_Table_Target = "Database Connections\\SQL_DB(ks204060).sde\\ArcSDE.dbo.gis" # Create FieldMappings object and load the target dataset fieldmappings = arcpy.FieldMappings() fieldmappings.addTable(WildFire_Table_Target) inputfields = [field.name for field in arcpy.ListFields(shpPath) if not field.required] for inputfield in inputfields: # Iterate through each FieldMap in the FieldMappings # for i in range(fieldmappings.fieldCount): fieldmap = fieldmappings.getFieldMap(i) #arcpy.AddMessage(fieldmap.getInputFieldName(0)) # If the field name from the target dataset matches to a validated input field name # if fieldmap.getInputFieldName(0) == inputfield.replace("", ""): # Add the input field to the FieldMap and replace the old FieldMap with the new # fieldmap.addInputField(shpPath, inputfield) fieldmappings.replaceFieldMap(i, fieldmap) break # Process: Append arcpy.Append_management(shpPath, WildFire_Table_Target, "NO_TEST", fieldmappings) print e.message arcpy.AddError(e.message)
... View more
02-22-2013
05:28 AM
|
0
|
0
|
520
|
POST
|
I am not exactly sure what your line 41 would be. i would assume you changed the code as least a little bit so my line 41 is not the same as yours. If you can post your code and state the text of the line that is giving you issues I can see if I can identify the issue. When posting your code make sure it posts with the correct indents and line breaks or it could make it look like you have more problems that aren;t necesarily in your code. Hi I guess the error related to this line: arcpy.Append_management(shpPath, WildFire_Table_Target, "NO_TEST", fieldmappings) I did not change your code, I got it from your answer to TOM. I wonder if you would mind to email your model (meriyaloot@gmail.com) regards
... View more
02-21-2013
11:24 AM
|
0
|
0
|
520
|
POST
|
Just be sure to check your python code to make sure none of the lines are wrapping on you. Does it say what line the indentation error is on? There is one input parameter scripted in this sample. infile = arcpy.GetParameterAsText(0). If you need more you can just take a similar appraoch. The error is for Line 41.
... View more
02-20-2013
07:40 PM
|
0
|
0
|
520
|
POST
|
Sorry I got ahead of you there. Because I needed to perform the field mapping on the fly i switched from using a model to using a python script. The input parameter type is going to be "File" in any case. In the script below, "infile = arcpy.GetParameterAsText(0)" is going to get the input file as a File type parameter. Then you can use the file as you please. You will see when you run this in desktop you have a file browser that you can use to browse to a file of your choice. Once you get that to run succesfully you can publish as a service. With the service you will need to get the itemID of the uploaded file and use that as an input parameter like itemID:"i83fa38d5-69e8-40c0-bd9c-30beb643e522".
import arcpy, os, zipfile
infile = arcpy.GetParameterAsText(0)
outpath, outfileext = os.path.splitext(infile)
filename = outpath.split('\\')[-1]
try:
# unzip file
fireZip = zipfile.ZipFile(infile, 'r')
fireZip.extractall(outpath)
fireZip.close()
shpPath = outpath + "\\" + filename + ".shp"
arcpy.AddMessage("Finished unzipping file.")
# Local variables:
WildFire_Table_Target = "Database Connections\\SQL_DB(TEST Server).sde\\ArcSDE.dbo.WILDFIREPERIM"
# Create FieldMappings object and load the target dataset
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(WildFire_Table_Target)
inputfields = [field.name for field in arcpy.ListFields(shpPath) if not field.required]
for inputfield in inputfields:
# Iterate through each FieldMap in the FieldMappings
#
for i in range(fieldmappings.fieldCount):
fieldmap = fieldmappings.getFieldMap(i)
#arcpy.AddMessage(fieldmap.getInputFieldName(0))
# If the field name from the target dataset matches to a validated input field name
#
if fieldmap.getInputFieldName(0) == inputfield.replace("", ""):
# Add the input field to the FieldMap and replace the old FieldMap with the new
#
fieldmap.addInputField(shpPath, inputfield)
fieldmappings.replaceFieldMap(i, fieldmap)
break
# Process: Append
arcpy.Append_management(shpPath, WildFire_Table_Target, "NO_TEST", fieldmappings)
except Exception as e:
print e.message
arcpy.AddError(e.message)
Hi I tested your code, but it return this error: IndentationError: unindent does not match any outer indentation level How should I set script input and output parameters?
... View more
02-19-2013
01:55 PM
|
0
|
0
|
825
|
POST
|
The following code (10.1 + only) walks through a directory and finds FeatureClasses (this example assumes a folder of "zip" files). It then copies each one into a fGDB. You can change what it does, but the logic in it should start you off. You'll notice that a directory is created inside the scratchFolder (the variable "ZipFolder") - this is where the uploaded ZipFile is extracted to. Then the code looks in there.
import arcpy
import zipfile
import os
inFile = arcpy.GetParameterAsText(0)
# Create a folder in the scratch directory to extract zip to
zipFolder = os.path.join(arcpy.env.scratchFolder, "zipContents")
os.mkdir(zipFolder)
# Extract the zip contents
zip2Extract = zipfile.ZipFile(inFile, 'r')
zip2Extract.extractall(zipFolder)
zip2Extract.close()
# Create a folder in the scratch directory to hold the fgdb which will be downloaded
fgdbFolder = os.path.join(arcpy.env.scratchFolder, "fgdbOutput")
os.mkdir(fgdbFolder)
# Work through all the FeatureClasses inside the extracted zip folder
for dirpath, dirnames, filenames in arcpy.da.Walk(zipFolder, datatype="FeatureClass"):
for filename in filenames:
# You could replace the code below here with your own code to do what you want....
arcpy.AddMessage("Copying: {}".format(filename))
# Strip .shp from the filename when merging shapefiles
if filename.endswith("shp"):
outFilename = filename[:-4]
else:
outFilename = filename
# Copy each featureclass into the output.gdb
arcpy.CopyFeatures_management(os.path.join(dirpath, filename),
os.path.join(fgdbFolder, "output.gdb", outFilename))
Hi I have this error: Traceback (most recent call last): File "C:\Users\user1\Documents\getfeature.py", line 13, in <module> zip2Extract = zipfile.ZipFile(inFile, 'r') File "C:\Python27\ArcGIS10.1\Lib\zipfile.py", line 699, in __init__ self.fp = open(file, modeDict[mode]) IOError: [Errno 13] Permission denied: u'C:\\Users\\user1\\Documents\\ArcGIS\\scratch\\ZipFolder'
... View more
02-17-2013
08:57 AM
|
0
|
0
|
874
|
POST
|
There are a lot of open questions, here. Is the un-zipped file a viable input for whatever you are trying to do otherwise? yes, Un-zipped file should be an input for other parts of my model. for example user zipped his shape file and he want to convert his shape file to other coordinate system.
... View more
02-13-2013
02:57 AM
|
0
|
0
|
234
|
POST
|
I have a model that unzip a zip file. I can unzip a zip file but I can not use extracted zip file as an intermediate data for continuing my model. Please help me. Regards
... View more
02-12-2013
08:52 AM
|
0
|
2
|
499
|
POST
|
My apologies, the da.Walk command was added at 10.1 Service Pack 1. Based on the message I'm guessing you have 10.1 final (no service packs). If you're able to install the service pack it'll fix that. Any solution?
... View more
02-12-2013
08:46 AM
|
0
|
0
|
874
|
POST
|
My apologies, the da.Walk command was added at 10.1 Service Pack 1. Based on the message I'm guessing you have 10.1 final (no service packs). If you're able to install the service pack it'll fix that. Hi Any solution? I heard Khimba is a geoprocessing manager. I saw your project about airlines. Solving my problem is not hard for you:) Regards
... View more
02-06-2013
10:07 AM
|
0
|
0
|
874
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|