Save output raster and automatically open in ArcMap? Planned maintenance scheduled April...
How do I stop a creek from eroding my steep embankment?
What makes black pepper strong or mild?
What do you call a phrase that's not an idiom yet?
Why does Python start at index -1 when indexing a list from the end?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Should I call the interviewer directly, if HR aren't responding?
Why is black pepper both grey and black?
Using et al. for a last / senior author rather than for a first author
How to find all the available tools in macOS terminal?
How can players work together to take actions that are otherwise impossible?
Is 1 ppb equal to 1 μg/kg?
Antler Helmet: Can it work?
Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?
Do I really need recursive chmod to restrict access to a folder?
Why are there no cargo aircraft with "flying wing" design?
Are my PIs rude or am I just being too sensitive?
How can I fade player when goes inside or outside of the area?
Is it true that "carbohydrates are of no use for the basal metabolic need"?
If a contract sometimes uses the wrong name, is it still valid?
Right-skewed distribution with mean equals to mode?
The logistics of corpse disposal
What's the purpose of writing one's academic bio in 3rd person?
Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?
If Jon Snow became King of the Seven Kingdoms what would his regnal number be?
Save output raster and automatically open in ArcMap?
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?I am using Mosaic to New Raster for AvgMin temp for each month, I need to reference from which month any given pixel in the output was populated fromArcMap will not open?Spatial join in ArcMap vs. ArcPy (how to make them the same)Saving MXDs to older version of ArcMap automatically?Classifying fields and getting statistics in ArcMap?How to create a single raster based on the values of three rasters (Conditional)?Computing 2 fields on basis of 3rd field and getting output in new field?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I want to reclass (by Table) raster files, then perform raster addition of the output (reclassed) rasters, then automatically display the final output (raster SUM) in ArcMap. This is the code that I created. Lines 1-32 works well, but when I add line 33
This error will appear:
"______, line 33, in SUM.save(SUM) TypeError: type
is not supported"
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os.path
# Set environment settings
path = "mypath"
env.workspace = path.replace("\","/")
#To overwrite existing files
arcpy.env.overwriteOutput = True
# Local variables:
F1 = "raster1"
F2 = "raster"
TABLE = "F.dbf" #Table to reclass raster
F1_REC = "raster1_reclass"
F2_REC = "raster2_reclas"
SUM = "sum.tif"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Reclass by Table F1
arcpy.gp.ReclassByTable_sa(F1, TABLE, "F1_FROM", "F1_TO", "F2_RE", F1_REC, "DATA")
# Reclass by Table F2
arcpy.gp.ReclassByTable_sa(F2, TABLE, "F2_FROM", "F2_TO", "F2_RE", F2_REC, "DATA")
# Process: Add F1_REC and F2_REC
SUM = Raster(F1_REC) + Raster(F2_REC)
SUM.save(SUM)
python arcgis-10.6
New contributor
add a comment |
I want to reclass (by Table) raster files, then perform raster addition of the output (reclassed) rasters, then automatically display the final output (raster SUM) in ArcMap. This is the code that I created. Lines 1-32 works well, but when I add line 33
This error will appear:
"______, line 33, in SUM.save(SUM) TypeError: type
is not supported"
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os.path
# Set environment settings
path = "mypath"
env.workspace = path.replace("\","/")
#To overwrite existing files
arcpy.env.overwriteOutput = True
# Local variables:
F1 = "raster1"
F2 = "raster"
TABLE = "F.dbf" #Table to reclass raster
F1_REC = "raster1_reclass"
F2_REC = "raster2_reclas"
SUM = "sum.tif"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Reclass by Table F1
arcpy.gp.ReclassByTable_sa(F1, TABLE, "F1_FROM", "F1_TO", "F2_RE", F1_REC, "DATA")
# Reclass by Table F2
arcpy.gp.ReclassByTable_sa(F2, TABLE, "F2_FROM", "F2_TO", "F2_RE", F2_REC, "DATA")
# Process: Add F1_REC and F2_REC
SUM = Raster(F1_REC) + Raster(F2_REC)
SUM.save(SUM)
python arcgis-10.6
New contributor
What happens when the code is run? How is that different from your expectations? What is your question? Please Edit the question.
– Vince
5 hours ago
You should probably break this into two separate questions: 1. How do I save an output raster? 2. How do I open a saved raster in ArcMap from Python? They are completely separate issues, and questions here should be about a single concise issue.
– Son of a Beach
5 hours ago
You're overwriting yourSUM = "sum.tif"
string variable withSUM = Raster(F1_REC) + Raster(F2_REC)
and then trying to pass yourSUM
Raster object toSUM.save()
which is expecting a string. Use something likesum_raster = Raster(F1_REC) + Raster(F2_REC)
andsum_raster.save(SUM)
S
– user2856
4 hours ago
add a comment |
I want to reclass (by Table) raster files, then perform raster addition of the output (reclassed) rasters, then automatically display the final output (raster SUM) in ArcMap. This is the code that I created. Lines 1-32 works well, but when I add line 33
This error will appear:
"______, line 33, in SUM.save(SUM) TypeError: type
is not supported"
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os.path
# Set environment settings
path = "mypath"
env.workspace = path.replace("\","/")
#To overwrite existing files
arcpy.env.overwriteOutput = True
# Local variables:
F1 = "raster1"
F2 = "raster"
TABLE = "F.dbf" #Table to reclass raster
F1_REC = "raster1_reclass"
F2_REC = "raster2_reclas"
SUM = "sum.tif"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Reclass by Table F1
arcpy.gp.ReclassByTable_sa(F1, TABLE, "F1_FROM", "F1_TO", "F2_RE", F1_REC, "DATA")
# Reclass by Table F2
arcpy.gp.ReclassByTable_sa(F2, TABLE, "F2_FROM", "F2_TO", "F2_RE", F2_REC, "DATA")
# Process: Add F1_REC and F2_REC
SUM = Raster(F1_REC) + Raster(F2_REC)
SUM.save(SUM)
python arcgis-10.6
New contributor
I want to reclass (by Table) raster files, then perform raster addition of the output (reclassed) rasters, then automatically display the final output (raster SUM) in ArcMap. This is the code that I created. Lines 1-32 works well, but when I add line 33
This error will appear:
"______, line 33, in SUM.save(SUM) TypeError: type
is not supported"
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
import os.path
# Set environment settings
path = "mypath"
env.workspace = path.replace("\","/")
#To overwrite existing files
arcpy.env.overwriteOutput = True
# Local variables:
F1 = "raster1"
F2 = "raster"
TABLE = "F.dbf" #Table to reclass raster
F1_REC = "raster1_reclass"
F2_REC = "raster2_reclas"
SUM = "sum.tif"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Reclass by Table F1
arcpy.gp.ReclassByTable_sa(F1, TABLE, "F1_FROM", "F1_TO", "F2_RE", F1_REC, "DATA")
# Reclass by Table F2
arcpy.gp.ReclassByTable_sa(F2, TABLE, "F2_FROM", "F2_TO", "F2_RE", F2_REC, "DATA")
# Process: Add F1_REC and F2_REC
SUM = Raster(F1_REC) + Raster(F2_REC)
SUM.save(SUM)
python arcgis-10.6
python arcgis-10.6
New contributor
New contributor
edited 3 mins ago
Taras
2,3003729
2,3003729
New contributor
asked 5 hours ago
JCBJCB
11
11
New contributor
New contributor
What happens when the code is run? How is that different from your expectations? What is your question? Please Edit the question.
– Vince
5 hours ago
You should probably break this into two separate questions: 1. How do I save an output raster? 2. How do I open a saved raster in ArcMap from Python? They are completely separate issues, and questions here should be about a single concise issue.
– Son of a Beach
5 hours ago
You're overwriting yourSUM = "sum.tif"
string variable withSUM = Raster(F1_REC) + Raster(F2_REC)
and then trying to pass yourSUM
Raster object toSUM.save()
which is expecting a string. Use something likesum_raster = Raster(F1_REC) + Raster(F2_REC)
andsum_raster.save(SUM)
S
– user2856
4 hours ago
add a comment |
What happens when the code is run? How is that different from your expectations? What is your question? Please Edit the question.
– Vince
5 hours ago
You should probably break this into two separate questions: 1. How do I save an output raster? 2. How do I open a saved raster in ArcMap from Python? They are completely separate issues, and questions here should be about a single concise issue.
– Son of a Beach
5 hours ago
You're overwriting yourSUM = "sum.tif"
string variable withSUM = Raster(F1_REC) + Raster(F2_REC)
and then trying to pass yourSUM
Raster object toSUM.save()
which is expecting a string. Use something likesum_raster = Raster(F1_REC) + Raster(F2_REC)
andsum_raster.save(SUM)
S
– user2856
4 hours ago
What happens when the code is run? How is that different from your expectations? What is your question? Please Edit the question.
– Vince
5 hours ago
What happens when the code is run? How is that different from your expectations? What is your question? Please Edit the question.
– Vince
5 hours ago
You should probably break this into two separate questions: 1. How do I save an output raster? 2. How do I open a saved raster in ArcMap from Python? They are completely separate issues, and questions here should be about a single concise issue.
– Son of a Beach
5 hours ago
You should probably break this into two separate questions: 1. How do I save an output raster? 2. How do I open a saved raster in ArcMap from Python? They are completely separate issues, and questions here should be about a single concise issue.
– Son of a Beach
5 hours ago
You're overwriting your
SUM = "sum.tif"
string variable with SUM = Raster(F1_REC) + Raster(F2_REC)
and then trying to pass your SUM
Raster object to SUM.save()
which is expecting a string. Use something like sum_raster = Raster(F1_REC) + Raster(F2_REC)
and sum_raster.save(SUM)
S– user2856
4 hours ago
You're overwriting your
SUM = "sum.tif"
string variable with SUM = Raster(F1_REC) + Raster(F2_REC)
and then trying to pass your SUM
Raster object to SUM.save()
which is expecting a string. Use something like sum_raster = Raster(F1_REC) + Raster(F2_REC)
and sum_raster.save(SUM)
S– user2856
4 hours ago
add a comment |
1 Answer
1
active
oldest
votes
You have asked two separate questions. I will attempt to answer the second question, which I think is:
How do I use Python to open a saved raster in an ArcMap document?
A Python script like the following should do it:
import arcpy, os
rasterPath = "C:/some/path/to/a/raster"
mapFileTemplatePath = "C:/some/template/folder/blank_map_file.mxd"
newMapFilePath = "C:/some/other/folder/new_map_file.mxd"
mxd = arcpy.mapping.MapDocument(mapFileTemplatePath) # Load the existing map document from disk (but not in ArcMap)
df = arcpy.mapping.ListDataFrames(mxd)[0] # Get the first data frame in the map document
rasterLayer = arcpy.mapping.Layer(rasterPath) # Create a mapping layer from the raster path
arcpy.mapping.AddLayer(df, rasterLayer) # Add the layer to the map document
mxd.saveACopy(newMapFilePath) # Save the map document
os.startfile(newMapFilePath) # Tell the operating system to open the map document - if it has a .mxd extension, it should open in ArcMap by default
arcpy cannot create a new MXD from scratch, so you always have to start with an existing MXD. Therefore it is useful to have a blank (or otherwise suitably populated/configured) MXD file in a known location ready for this task.
This is all done with the arcpy.mapping
module.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
JCB is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318912%2fsave-output-raster-and-automatically-open-in-arcmap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have asked two separate questions. I will attempt to answer the second question, which I think is:
How do I use Python to open a saved raster in an ArcMap document?
A Python script like the following should do it:
import arcpy, os
rasterPath = "C:/some/path/to/a/raster"
mapFileTemplatePath = "C:/some/template/folder/blank_map_file.mxd"
newMapFilePath = "C:/some/other/folder/new_map_file.mxd"
mxd = arcpy.mapping.MapDocument(mapFileTemplatePath) # Load the existing map document from disk (but not in ArcMap)
df = arcpy.mapping.ListDataFrames(mxd)[0] # Get the first data frame in the map document
rasterLayer = arcpy.mapping.Layer(rasterPath) # Create a mapping layer from the raster path
arcpy.mapping.AddLayer(df, rasterLayer) # Add the layer to the map document
mxd.saveACopy(newMapFilePath) # Save the map document
os.startfile(newMapFilePath) # Tell the operating system to open the map document - if it has a .mxd extension, it should open in ArcMap by default
arcpy cannot create a new MXD from scratch, so you always have to start with an existing MXD. Therefore it is useful to have a blank (or otherwise suitably populated/configured) MXD file in a known location ready for this task.
This is all done with the arcpy.mapping
module.
add a comment |
You have asked two separate questions. I will attempt to answer the second question, which I think is:
How do I use Python to open a saved raster in an ArcMap document?
A Python script like the following should do it:
import arcpy, os
rasterPath = "C:/some/path/to/a/raster"
mapFileTemplatePath = "C:/some/template/folder/blank_map_file.mxd"
newMapFilePath = "C:/some/other/folder/new_map_file.mxd"
mxd = arcpy.mapping.MapDocument(mapFileTemplatePath) # Load the existing map document from disk (but not in ArcMap)
df = arcpy.mapping.ListDataFrames(mxd)[0] # Get the first data frame in the map document
rasterLayer = arcpy.mapping.Layer(rasterPath) # Create a mapping layer from the raster path
arcpy.mapping.AddLayer(df, rasterLayer) # Add the layer to the map document
mxd.saveACopy(newMapFilePath) # Save the map document
os.startfile(newMapFilePath) # Tell the operating system to open the map document - if it has a .mxd extension, it should open in ArcMap by default
arcpy cannot create a new MXD from scratch, so you always have to start with an existing MXD. Therefore it is useful to have a blank (or otherwise suitably populated/configured) MXD file in a known location ready for this task.
This is all done with the arcpy.mapping
module.
add a comment |
You have asked two separate questions. I will attempt to answer the second question, which I think is:
How do I use Python to open a saved raster in an ArcMap document?
A Python script like the following should do it:
import arcpy, os
rasterPath = "C:/some/path/to/a/raster"
mapFileTemplatePath = "C:/some/template/folder/blank_map_file.mxd"
newMapFilePath = "C:/some/other/folder/new_map_file.mxd"
mxd = arcpy.mapping.MapDocument(mapFileTemplatePath) # Load the existing map document from disk (but not in ArcMap)
df = arcpy.mapping.ListDataFrames(mxd)[0] # Get the first data frame in the map document
rasterLayer = arcpy.mapping.Layer(rasterPath) # Create a mapping layer from the raster path
arcpy.mapping.AddLayer(df, rasterLayer) # Add the layer to the map document
mxd.saveACopy(newMapFilePath) # Save the map document
os.startfile(newMapFilePath) # Tell the operating system to open the map document - if it has a .mxd extension, it should open in ArcMap by default
arcpy cannot create a new MXD from scratch, so you always have to start with an existing MXD. Therefore it is useful to have a blank (or otherwise suitably populated/configured) MXD file in a known location ready for this task.
This is all done with the arcpy.mapping
module.
You have asked two separate questions. I will attempt to answer the second question, which I think is:
How do I use Python to open a saved raster in an ArcMap document?
A Python script like the following should do it:
import arcpy, os
rasterPath = "C:/some/path/to/a/raster"
mapFileTemplatePath = "C:/some/template/folder/blank_map_file.mxd"
newMapFilePath = "C:/some/other/folder/new_map_file.mxd"
mxd = arcpy.mapping.MapDocument(mapFileTemplatePath) # Load the existing map document from disk (but not in ArcMap)
df = arcpy.mapping.ListDataFrames(mxd)[0] # Get the first data frame in the map document
rasterLayer = arcpy.mapping.Layer(rasterPath) # Create a mapping layer from the raster path
arcpy.mapping.AddLayer(df, rasterLayer) # Add the layer to the map document
mxd.saveACopy(newMapFilePath) # Save the map document
os.startfile(newMapFilePath) # Tell the operating system to open the map document - if it has a .mxd extension, it should open in ArcMap by default
arcpy cannot create a new MXD from scratch, so you always have to start with an existing MXD. Therefore it is useful to have a blank (or otherwise suitably populated/configured) MXD file in a known location ready for this task.
This is all done with the arcpy.mapping
module.
answered 1 hour ago
Son of a BeachSon of a Beach
1,586719
1,586719
add a comment |
add a comment |
JCB is a new contributor. Be nice, and check out our Code of Conduct.
JCB is a new contributor. Be nice, and check out our Code of Conduct.
JCB is a new contributor. Be nice, and check out our Code of Conduct.
JCB is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318912%2fsave-output-raster-and-automatically-open-in-arcmap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What happens when the code is run? How is that different from your expectations? What is your question? Please Edit the question.
– Vince
5 hours ago
You should probably break this into two separate questions: 1. How do I save an output raster? 2. How do I open a saved raster in ArcMap from Python? They are completely separate issues, and questions here should be about a single concise issue.
– Son of a Beach
5 hours ago
You're overwriting your
SUM = "sum.tif"
string variable withSUM = Raster(F1_REC) + Raster(F2_REC)
and then trying to pass yourSUM
Raster object toSUM.save()
which is expecting a string. Use something likesum_raster = Raster(F1_REC) + Raster(F2_REC)
andsum_raster.save(SUM)
S– user2856
4 hours ago