Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Re: exporting x&y values (coordinates) from graph builder once jmp automatically...

Topic Options

- Start Article
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Apr 18, 2019 7:22 AM
(1071 views)

How can I export x&y coordinates for the centroid points jmp automatically finds within my polygons (n=2455) on a graph builder map? I would like to make lat/long columns for these points in order to make contour and heat maps, but all I have currently are the many vertices coordinates for the mapshape polygons. These are municipalities in Mexico, so there is no determined point location (city) for the ad on to find (if it could), but the centroid points jmp finds is perfect for me. I don't know how to write script.

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Fever,

Here is a quick script I wrote to find the centroids based on the XY shape file. Please try and let me know how it works for you.

```
dt = Current Data Table();
shapeList = Associative Array( Column( dt, "Shape ID" ) << get values ) << get keys;
dtCentroids = New Table("Centroids", New Column( "Shape ID", numeric, continuous ),
New Column( "X", numeric continuous ),
New Column( "Y", numeric, continuous )
);
For( i = 1, i <= N Items( shapeList ), i++,
targetRows = dt << get rows where( Column( dt, "Shape ID" )[Row()] == shapeList[i] );
centroid = Polygon Centroid( Column( dt, "X" )[targetRows], Column( dt, "Y" )[targetRows] );
dtCentroids << add rows( 1, "at end" );
Column( dtCentroids, "Shape ID" )[i] = i;
Column( dtCentroids, "X" )[i] = centroid[1];
Column( dtCentroids, "Y" )[i] = centroid[2];
);
```

7 REPLIES 7

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Fever,

What I did was take the mean X and Y values (using table>summary) for each of my shapes in the XY polygon file. This is not really a centriod, but it worked well enough for my purposes.

John

@fever wrote:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: exporting x

Thanks, yes that works w most of the shapes. Good enough from a distance. Thought maybe there were a simple way to access the automatically generated centroid data

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Fever,

Here is a quick script I wrote to find the centroids based on the XY shape file. Please try and let me know how it works for you.

```
dt = Current Data Table();
shapeList = Associative Array( Column( dt, "Shape ID" ) << get values ) << get keys;
dtCentroids = New Table("Centroids", New Column( "Shape ID", numeric, continuous ),
New Column( "X", numeric continuous ),
New Column( "Y", numeric, continuous )
);
For( i = 1, i <= N Items( shapeList ), i++,
targetRows = dt << get rows where( Column( dt, "Shape ID" )[Row()] == shapeList[i] );
centroid = Polygon Centroid( Column( dt, "X" )[targetRows], Column( dt, "Y" )[targetRows] );
dtCentroids << add rows( 1, "at end" );
Column( dtCentroids, "Shape ID" )[i] = i;
Column( dtCentroids, "X" )[i] = centroid[1];
Column( dtCentroids, "Y" )[i] = centroid[2];
);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Glad to hear it worked. Happy JMPing!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

FWIW, here is an alternative that uses plotted data directly:

```
NamesDefaultToHere(1);
// Table
dt = New Table( "Some States",
New Column(
"State",
Character,
Nominal,
Set Values(
{"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii"}
)
)
);
// Map
gb = dt << Graph Builder(
Show Control Panel( 0 ),
Variables( Shape( :State ) ),
Elements( Points( Legend( 5 ) ) )
);
// Get x and y values from marker seg
gbRep = Report(gb);
frame = gbRep[FrameBox(1)];
mySeg = (frame << Find Seg( Marker Seg( 1 ) ));
xVals = mySeg << Get X Values;
yVals = mySeg << Get Y Values;
dt2 = asTable(xVals||yVals, << columnNames({"X", "Y"}));
dt2 << setName("Map Shape Centroids");
```