Read a feature class in a variable - arcpy

Let's assume I have a geodatabase "database.gdb", and inside this database there is a feature class called "feature".
How can I load this feature in memory using arcpy? I have searched into the arcpy
docs and couldn't find anything useful.
I tried to use Copy_management and CreateFeatureclass_management but its look like these methods expects files instead of variables.

You can use SearchCursor:
for example:
fc = 'database.gdb/feature'
columns = ['column1', 'column2']
results = []
with arcpy.da.SearchCursor(fc, columns) as cursor:
for row in cursor:
results.append([row[0], row[1]])
in this case, the whole "feature" feature class is stored in the list "results"


Getting buddy class information?

I'm trying to read buddy class metadata information for usage outside of the normal mvc 2 validation process. I thought it would be as simple as saying:
DataAnnotationsModelMetadataProvider metadataProvider = new DataAnnotationsModelMetadataProvider();
var metaData = metadataProvider.GetMetadataForType(() => new T(), typeof (T));
That works, but is returning me the entire types metadata information and not just what is in the buddy information. According to the MVC2 source ( It uses the buddy class support from DataAnnotations, ) it should support getting the buddy data information but I don't see the part in the code where it reflects into the Metadatatype() attribute.
Generally confused here. Did I miss an overload or something?
I had the same problem. I have looked at literally 30 maybe 40 tutorials about why this Entity Framework "Database First" partial classes wasn't working. Then I found this post -- MVC 4 EF5 Database First set Default Values in Partial Class -- that gave the following suggestion:
belongs in the partial class generated by the EF, even though it will
be erased if and when you change the model. So your EF-generated file
should look like this:

set lazy as true during HQL execution time

In our application, we have various objects set to lazy false based on the application needs. However, in one of the use case we want to ignore all the lazy settings within the HBM files, and get ONLY the target object.
So the question is: is there a way to specify in the HQL to fetch ONLY the target object irrespective of the HBM settings?
you can use setFetchMode on the Criteria before it is executed to override the HBM file setting
Sorry, not sure if you understood your question.
If you have to implement it for a specific class, you can just use SetFetchMode.
var query = session.CreateCriteria(typeof(MyClass));
query.SetFetchMode("PropertyA", FetchMode.Select);
query.SetFetchMode("PropertyB", FetchMode.Select);
Note: for many-to-one references the entity class itself must be mapped with lazy=true. If not, NHibernate doesn't even create a proxy class for it.
This is the answer if you want to lazy load the type in a generic, type-independent way:
You could find them with the metadata and add fetch modes to a criteria
I didn't try it, but I would start with the following code:
var meta = sessionfactory.GetClassMetaData(typeof(MyClass));
var query = session.CreateCriteria(typeof(MyClass));
for(int index = 0; index < meta.PropertyType.Length; index++)
if (meta.PropertyType[index] == NHibernateUtil.Entity)
query.SetFetchMode(meta.PropertyNames[index], FetchMode.Select);
This doesn't include collections. They are probably found with factory.GetCollectionMetadata(roleName), but you need to find out the roleName.

Replacing json retrieval with database retrieval in project

Apologies if I'm not providing enough information here, I'm new to android/java and am learning by combining elements of various example projects.
I have a working VerticalGridFragment page for an Android TV project (using leanback) that loads album cover art and details in columns and rows. It borrows heavily from the googlesamples example on github.
Using a test music_database_proto.json file in the format of:
"cards": [
"type": "GRID_SQUARE",
"title": "Around the World in a Day",
"artist": "Prince and the Revolution",
"description": "Prince and the Revolution",
"groupType": 0,
"tagID": 0,
"localImageResource": "food_01"
I can then load this using a createRows() function (from the same sample project) using:
PresenterSelector cardPresenterSelector = new CardPresenterSelector(getActivity());
mAdapter = new ArrayObjectAdapter(cardPresenterSelector);
String json = Utils.inputStreamToString(getResources().
CardRow row = new Gson().fromJson(json, CardRow.class);
mAdapter.addAll(0, row.getCards());
Which uses the sample projects classes of CardRow.class, Card.class and their various supporting classes in the example.
I've implemented an SQLite database that successfully initiates and I can call various results in the Logs of Android Studio. I don't know where to start with inserting results from the database as Cards that I can load into the VerticalGridFragment, replacing the function of the json file?
I thought it would be as simple as creating a List<Card> from database results and adding this to mAdapter using mAdapter.addAll. However, I've had little luck in implementing a List of Card objects using iterating code. Desperately, I thought I should turn database results into a json string and feed them into the existing code I showed above?
Any help appreciated. The database is as basic as a recreation of the json variables and can be adjusted to suit.
What exactly do you mean by However, I've had little luck in implementing a List of Card objects using iterating code.? If you're calling mAdapter.addAll(0, cards) with a list of cards, it should work as you desire.
Are you having difficulty extracting the list of cards from your SQLite database? You can rely on this link which has the following answer. I've modified it slightly to be about Card.class. You'll also need to add a constructor to the Card object since they provided it to you assuming you'd use #SerializedName to initialize it. The below example assumes you've added a constructor that looks like public Card(String title, String description).
List<Card> cardsList = new ArrayList<Card>();
database = openOrCreateDatabase("your_db", SQLiteDatabase.OPEN_READWRITE, null);
c= database.rawQuery(QUERY, null);
Card card = new Card(c.getString(c.getColumnIndex("title")),
The example is really just a starting point, but they encourage you to customize any of those classes within the sample to better fit your needs.
I also like that you're trying to learn SQLite since it's a piece of Android (and mobile development in general) that is good to be familiar with. You can also use a library like Stetho by Facebook to make sure your SQLite tables actually contain the correct data. It makes debugging a little easier.
Realm for android would be your best choice.
Its easy to use and its faster than SQLite.
And its just few lines of code needed to get things started. Please check it out. I'm recently tunred out to be Realm Evangelist(not officially) after falling in love with it. Only setback would be getting used fluent interface based Queries and it happens only if your queries are too complicated.

ORM for Spring-MongoDB integration with native querying support

I am a new to using Mongo DB and exploring the frameworks around for migrating from mysql to mongodb. So far from my findings I have been able to figure out SpringMongo as the best solution to my requirements.
The only problem is that instead of using a DSL based or abstract querying mechanism, I wished the framework allowed me to pass plain json string as arguments to the different methods exposed by the API(find, findOne) so that the query parameters can be written out to an external file (using a key to refer) and passed to the methods by reading and parsing at run time. But the framework should be capable of mapping the results to the domain objects.
Is there a way in spring-mongo to achieve this? Or is there any other frameworks on the same lines
You could use Spring Data to do that, just use the BasicQuery class instead of Query class. Your code will look like the following:
/* Any arbitrary string that could to parsed to DBObject */
Query q = new BasicQuery("{ filter : true }");
List<Entity> entities = this.template.find(q, Entity.class);
If you want more details:
Well I got to find this one in the Spring data MongoOperations...
String jsonCommand = "{username: 'mickey'}";
MongoOperations mongoOps = //get mongooperations implemantation
It returns an instance of CommandResult that encapsulates the result.

Create Index for Full Text Search in Google App Engine

I'm reading the documentation on full text search api (java) in google app engine at They have example on getting the index:
public Index getIndex() {
IndexSpec indexSpec = IndexSpec.newBuilder()
return SearchServiceFactory.getSearchService().getIndex(indexSpec);
How about on creating an index? How to create one?
You just did. You just created one.
public class IndexSpec
Represents information about an index. This class is used to fully specify the index you want to retrieve from the SearchService. To build an instance use the newBuilder() method and set all required parameters, plus optional values different than the defaults.
You can confirm this by looking at the SearchService
SearchService is also responsible for creating new indexes. For example:
SearchService searchService = SearchServiceFactory.getSearchService();
index = searchService.getIndex(IndexSpec.newBuilder().setName("myindex"));
Anyway, It seems your code will create a new index if it doesn't exist. That's what the docs suggest:
// Get the index. If not yet created, create it.
Index index = searchService.getIndex(
Now, what happens if you run the code again and change the Consistency? Do you have the same index with a different consistency? Is the index overwritten? I don't know. I would use the SearchService to lookup existing indexes instead of using code that might create them just to avoid trying to get an index in my code but changing the specs inadvertantly.
An Index is implicitly created when a document is written. Consistency is an attribute of the index, i.e. you can't have two indexes of the same name with different consistencies.