Modelbuilder: Calculate Values for field in an in_memory table

5488
6
Jump to solution
11-12-2015 01:06 PM
LinkElmore
New Contributor III

Question: What tool or set of tools in modelbuilder can be used to edit values in the field of an Esri table using the in_memory workspace?

My basic task is to pass two user supplied parameters (Lat and Long as doubles) to the XY EVENT LAYER tool, which requires a table as input.  I don't want to write out a table to disk for every time this process runs so I am hoping to use the in_memory workspace option for the CREATE TABLE tool.

I have tried using CALCULATE FIELD, referencing the relevant field from the in_memory table to pass the user supplied values (doubles). The tool runs fine but no output is written to the fields of the in_memory table, therefore nothing passes down the line to the XY EVENT LAYER tool and I get no geometry for output.

Is it possible to write to an in_memory table in this way?  Any suggestions on a simpler way to work this problem?

Thanks.

Export Graphic.png

0 Kudos
1 Solution

Accepted Solutions
FreddieGibson
Occasional Contributor III

I don't think that your original model is going to work. The create table will create a new blank table in memory, but you won't have any records for the Calculate Field to update. The Calculate Field tool cannot create new records in the table, so the output would be an empty table that is passed to the Create XY Event tool.

If you wanted this to work in its simplest form you could leverage a RecordSet parameter. This would just require that you provide a schema for the RecordSet. The below model worked for me. The dialog shown is how your users would provide the inputs to the RecordSet parameter. As a result of using the RecordSet users would be able to input multiple points.

Option_1.png

If you wanted to expose a variable for the two coordinates (i.e. a Double type parameter for the X_Coord and a Double type parameter for the Y_Coord) without using python you could accomplish this, but you wouldn't be able to use the Create Table tool without using the append tool. I would think that you'd need to have already created a table with a single row. You'd need to copy this table into memory, use calculate field against this to update the already available row, and then create your features from this. I was able to accomplish this with the below model.

option_3.png

View solution in original post

6 Replies
DarrenWiens2
MVP Honored Contributor

Have you tried stretching it all out linearly, not using precondtions? So, Create Table, then Calculate Field, then Calculate Field, and finally Make XY Event Layer. I use Python rather than ModelBuilder - perhaps the linear model is exactly equivalent to using preconditions, but I've never had much luck getting them to work as I want.

I don't think 'in_memory' is the culprit. As long as you're not running out of memory, it should function more or less like a FGDB feature class. Does it work if you save the file to disk?

0 Kudos
MikeCusi
Occasional Contributor II

I can't open your tbx, so I can't see how you've set it up but from the image, I can see that in_memory is not the output of your create table. Should it not be the input used for the calculate field?

0 Kudos
DarrenWiens2
MVP Honored Contributor

'in_memory' is the input 'out_path' parameter.

0 Kudos
MikeCusi
Occasional Contributor II

exactly. that is why it should be the input table for the next step which is the "calculate field'.

0 Kudos
DarrenWiens2
MVP Honored Contributor

'in_memory' isn't a table, it's a workspace. The table output from Create Table is 'in_memory\submittedLongLat%time%', which is the desired input for the next tools.

FreddieGibson
Occasional Contributor III

I don't think that your original model is going to work. The create table will create a new blank table in memory, but you won't have any records for the Calculate Field to update. The Calculate Field tool cannot create new records in the table, so the output would be an empty table that is passed to the Create XY Event tool.

If you wanted this to work in its simplest form you could leverage a RecordSet parameter. This would just require that you provide a schema for the RecordSet. The below model worked for me. The dialog shown is how your users would provide the inputs to the RecordSet parameter. As a result of using the RecordSet users would be able to input multiple points.

Option_1.png

If you wanted to expose a variable for the two coordinates (i.e. a Double type parameter for the X_Coord and a Double type parameter for the Y_Coord) without using python you could accomplish this, but you wouldn't be able to use the Create Table tool without using the append tool. I would think that you'd need to have already created a table with a single row. You'd need to copy this table into memory, use calculate field against this to update the already available row, and then create your features from this. I was able to accomplish this with the below model.

option_3.png