Tag Archives: ArcGIS

ESRI Attachments with ArcServer and Javascript

10 Dec
Upload Image from Phone Camera

Upload Image from Phone Camera

I was working on the following problem:

How can we take a photo of a GIS feature and put it on the network in a folder named after a property of the feature?

I started by creating a map that displayed the feature and grabbed the property value. I coded a popup for the feature that used a form to allow the uploading of images from a phone camera. The code for the form is below:

<form target=”_blank”‘+theaction+'” enctype=”multipart/form-data” method=”post” accept=”image/*;capture=camera”><input type=”file” name=”upload” multiple=”multiple”><br><input type=”submit” value=”Upload”></form>

The next step was handling the files the form sent on the server side. Using Node.js, I displayed the map and handled the file transfer from the form. The problem was solved.

Was it the best solution? No. Keeping the geometry and images separate means extra coordination – if a point is deleted we have to find the image as well.

The end goal was an image associated with a GIS feature. I came up with a better solution. We could just use a blob field and put the photo in the database as a field. As I was starting to work on it, I remembered ArcGIS allows attachments. It will accept a blob and handle the relation between the geometry and the point features. This would be the best solution.

I created my feature class and enabled attachments. Now, using the ESRI REST API, I can upload attachments (images) using a form with the action set to the url of the service:


This solution is much simpler than the Node.js solution. first, it doesn’t require a new server application – it uses our already running ArcServer. I don’t have to justify to the IT Department my use of Node.js – ArcServer is already allowed.  Finally, the relationship between the feature and the images are handled by ArcServer. If a point is deleted, so is the image.

My final application displays a map. When you click on the map a point is placed and a popup is opened. The popup contains a combo box that allows you to select the feature class for your point. Using the REST API, the point is added to the feature class. The popup content then changes to the attachment upload form. You can click the select button and the camera application is launched on your phone. Once an image is captured, you click submit and a new tab opens showing the result of the file upload. I have a separate map application that displays the points from the feature classes with a popup detailing the associated attachments for viewing and downloading.

Calling Python From PHP: A GIS Example

12 Nov

I showed in a past post how you could use Python and CherrPy to make web based GIS applications. While I think this is a great way to develop, I currently have WAMP installed and can run PHP through Apache without any extra configuration. I decided to take a look at how I could run my Python GIS Scripts through a PHP based website. It turns out that it is a rather simple task:

<?php exec(“C:\python25\python mygi.py”); ?>

That is all there is to it. Now let me give you an example of how I would use this:

  1. I want to create a website where a person can select one of my shapefiles and a toolbox and then have the output sent back to them. If you want you could even let them upload their own file then you run the tools on it – if they wanted the results for their ArcGIS Online maps and lacked processing tools.
  2. For simplicity, I will default to the Gi* toolbox.
  3. When they click submit, I will generate the Python code in the PHP and then run the script. Doing this allows me to customize all of my Python scripts based on user preference. I can plug user input in to all of my functions.
  4. Lastly, the website will hand back the zipped files.

Here is the code for the form.

<H3>Enter a file to run Gi*</H3>
<form name=”input” action=”gi.php” method=”get”>
Shapefile: <input type=”text” name=”shp”><br>
<input type=”submit” value=”Submit”>

Simply a text box to enter a file name and a submit button. The for calls gi.php, which contains:

<H1>Running Gi*</H1>
<h2>On file <?php echo $_GET[“shp”];  ?>

$py= fopen(‘mygi.py’, ‘w+’);
$header=’import arcgisscripting’.”\n”.’import zipfile’.”\n”;
$gp = ‘gp = arcgisscripting.create()’.”\n”.’gp.workspace = “C:\wamp\www\output”‘.”\n”;
$hs=’hs = gp.HotSpots(“‘.$_GET[“shp”].'”, “Score”, “HotSpots.shp”, “Fixed Distance Band”, “Euclidean Distance”, “None”, “2500”, “#”, “#”)’.”\n”;
$z=’zipped = zipfile.ZipFile(“C:\wamp\www\output\hotspots.zip”, mode=”w”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.shp”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.shx”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.prj”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.shp.xml”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.sbx”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.sbn”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.dbf”)’.”\n”.’zipped.close()’;

<H3>Wrote Python….Executing</H3>

<?php exec(“C:\python25\python mygi.py”); ?>


<a href=”/output/HotSpots.zip”>hotspots.zip</a>


The first thing the script does is print the name of the file they entered as an <H2>. Then the PHP opens a python file and writes the code. It then executes the code and returns an HREF to the zipfile. To make the actual Python code clear, I will include it:

import arcgisscripting
import zipfile

gp = arcgisscripting.create()
gp.workspace = “C:\wamp\www\output”
hs = gp.HotSpots(“Input.shp”, “Score”, “HotSpots.shp”, “Fixed Distance Band”, “Euclidean Distance”, “None”, “2500”, “#”, “#”)

zipfile.ZipFile(“C:\wamp\www\output\hotspots.zip”, mode=”w”)

I am still on Arc 9.3. That’s why you see the import of arcgisscripting. I believe in 10 it’s arcpy.

Import ArcGIS in to Revit

15 Jun

Saw a google search for importing GIS files in to revit. The way I move between GIS and CAD, because I don’t have ArcGIS, is using Autodesk Civil 3D. Civil includes Autodesk Map. You can simply go to the map menu and import. Select the SHP file, then export as AutoCAD. You can also draft and export a CAD file to SHPusing the same menus.

I am pretty sure that there is a toolbox in ArcGIS that will export a SHP as CAD. May require the data interoperability extension.

Remember, Revit does not like files that cover an area greater than 20 miles or so. You may need to crop your SHP.