Tag Info

Hot answers tagged

23

Use the field calculator (Layer>Open attribute table>Field Calculator/Ctrl+I or right click shapefile>Open attribute table>Field Calculator/Ctrl+I). There is an operator "area" that will calculate the area of each row in the table. All units will be calculated in the units of the projection, so you probably want to project it to a projection that uses feet ...


8

A nice Pythonic way of tackling this is to use the filter function, which takes two inputs: the value you'd like to exclude, and the input object (any interable). After that, just sum the result: def stack(*args): return sum(filter(None, args))


5

I don't think this is possible with the field calculator. If using a SQL Server or Oracle geodatabase, another alternative is to create a spatial view. In this scenario, Field3 would not be in your original feature class but calculated dynamically in your view.


5

This can also be done with Vector|Geometry Tools|Add/export geometry columns, which creates a new shapefile with area and perimeter (or length) columns added. Edit: (using the tool above, you can also unselect "save as new shape-file" in V1.8, the shapefile is now only updated!) Using the field calculator is probably a better idea, though, as it doesn't ...


5

If you like SQL, you can apply a Definition Query: IN('x','y','z') then process your field calculator results. Only the filtered records will be modified. If you want Python, it will look similar to the SQL: if !field1! in ("x","y","z"): f2 = "field1 is yep" [Added as solution] Or as a 1-liner without any preprocessing required: 'yes' if ...


5

Check if the resulting pixel values make sense (e.g. using the Identify tool). Also, if you change away from "greyscale" to "pseudocolor" (in the resulting layer's properties), the patterns should get visible (if they exist). In general, it's a good idea to use the stretch option in the lower right corner of the first tab. This way, even with the ...


4

There is a way that could be a little quicker as it uses a faster method to query the data. Right click on the layer Select "Query" Enter area > 10000 The layer will be filtered to only show that data Right click on the layer Click "Save As..." Save the filtered layer to a new file. Remove the query from the main layer using steps 1) and 2) This uses ...


4

Here is a technical document describing some of the basic VBA calculator functions, with links to some short walk-throughs. And here is some narrative (with examples) on using the Field Calculator and VBA. Remember that using VBA in the field calculator is only valid for 9.3.1 and not 10 (which uses python and VBScript).


4

@ustroetz answer is almost correct. However, it won't necessarily give you the correct results. When you mutate the list while iterating over it, you may skip some values. For example, if your list is defined as such: mylist = [None, 3,4,5,6,7, None, None, 4,65,23,6, None] and you use this code: for item in myList: if item is None: ...


3

Try reclassifying the corine raster in multiples of 10 eg Artificial surface = 10 Agricultural = 20 Forests = 30 etc Then reclassify the second image using values from 1 to 7 (1 for closed canopy, 2 for open etc) Sum the resultant reclassified rasters together you should get a raster with the values combined so for instance corine forest that is closed ...


3

Whenever I try out an algorithm that I'm unsure about, I'll test it with a stand-alone calculator using real numbers from the dataset first to see if it gives me the desired outcome. If the results look decent I then implement the algorithm and compare the output results to see if they're giving the same number (so the "Identify" tool that underdark ...


3

can you elaborate on your requirement a little more? It appears that you're trying to conditionally calculate the value of field 2 based on the value of field 1. you could do the entire operation in a python script using a combination of Mike's suggestion and an UpdateCursor something like this: cursor = gp.UpdateCursor(yourfeatureclass) row = ...


2

That needs to be treated as a function. In your code block: def AlnumField(field_value): if str(field_value).isalnum(): return 1 else: return 0 Then in your expression: AlnumField(!fieldx!) The !fieldname! notation is only respected in the expression, not the code block.


2

Select all areas bigger than 10,000 m2. Either: Open the attribute table of your polygon layer, and click on the 'area' attribute column (or 'acres' or whatever you used to name it when you calculated area) to sort by area. You can then select all the rows from the 10k m2 point on down, OR - Open the attribute table and click "advanced search". In the ...


2

this is a sumarize function. You will need to right click on the area field and hit summarize. Then add the value field and sum it. After you complete that you can join that table back to the original data using the id field. NOTE: it is advisable to not use the fid,OID field for your id. Just create a new field and calculate the value from fid into it.


2

Error 000539 means you have an error in your expression. This thread addresses a similar issue. This ArcGIS help document should help you better understand expression syntax. If you post the expression you used in the Raster Calculator someone may be able to evaluate it for you.


2

I like the expression you've put together - probably no solution in QGIS 1.8, but in QGIS 1.9-dev there's a floor() rounding function which rounds down: floor ($x) || '° ' || floor((($x) - floor ($x)) * 60) ||'\'' || substr( (tostring(((($x) - floor ($x)) * 60) - floor((($x) - floor ($x)) * 60)) * 60),1,5) || '"' Note the escaped apostrophe (\').


2

whuber seems to have it covered, but an alternative approach might involve taking the slope of a slope raster. The slope function of a DEM gives us the rate of elevation change, and taking the slope function of that would give us in the rate of change in slope. Ideally, the toe of slope would be located in areas with high rates of slope change. This ...


2

The formulation is (for GRASS 6.x and GRASS 7): if expression = True -> value of raster_a if expression = False -> nothing (null()) and: resulting_layer = (expression, True, False) so: raster_b = (if..., raster_a, null()) In the GRASS shell: r.mapcalc 'raster_b = if(raster_a > -0.15 && raster_a <0.15 ,raster_a,null())' with ...


1

Using spatial sql: SELECT *, ST_Area(the_geom) FROM Table more info SELECT *, ST_AsText(ST_Centroid(the_geom)) FROM Table more info


1

Given the Euclidean distance from urban areas, for instance you can reclassify it (0 for distance <= 50 ft, 1 elsewhere) using the Reclassify tool. (Alternatively, you can apply an equivalent conditional expression with the Raster Calculator... So you can choose the way you like). Then you should simply multiply the reclassified Euclidean distance with ...


1

The following python field calculator code should do the job: total = stack( !field1!, !field2!, !field3!) Pre-Logic Script Code: def stack(*args): myList = list(args) for item in myList: if item is None: myList.remove(item) return sum(myList)


1

The modulo operator can be used to do truncation, but the resulting expression would be very ugly. It is prettier to use string substitution, but unfortunately QGIS doesn't expose any strpos or similar functions. Use regexp_replace($x, '\\..*', '') to get the whole part and regexp_replace($x, '^[0-9]*\\.', '') to get the decimal part. Use toreal instead of ...


1

You can open field calculator and use a function like... ltrim [my_field] Then in field calculator you will see a save button. This will save a file that can be reloaded in caclulator. You can view this file in notepad (or other text editor). As blah238 said the knowledgebase article will help show what can and can't be used. NOTE: You will only be able ...


1

Is this simplification of your question correct: you have a polyline and a set of points on that polyline. You want to order these points in the "driving" sequence? One option is to use PostGIS. For each point split the polyline into two and then calculate the length of the first polyline part. This is your ordering function.


1

I'm not sure, I think you mean if a bus is on a line segment, determine all the bus stops that are closest to him, but yet still on the line? What you need to do here is: Create a line layer joining all the bus stops. for each segment, designate a "cost", that cost would be based on a formula: distance, intersection type, street type, capacity, volume, ...


1

"I have to keep running the calculation every time I add data. Cannot it not update automatically?" Yes Manually. If have the VB skills you can semi-automate it Create a custom tool in Visual Basic Editor in ArcMap.Each time you want to calculate values for a field, you can just press on this custom tool icon button. Fastest Method: The easiest and ...


1

I think that you may be best creating a model in ArcToolbox specific for this dataset so when you update the dataset you just run the model. If you haven't used model builder before then this introduction may help: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/What_is_ModelBuilder/002w00000001000000/ ...and there is a tutorial here: ...



Only top voted, non community-wiki answers of a minimum length are eligible